Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "rtl/ustring.hxx"
30 : : #include "vcl/scrbar.hxx"
31 : : #include "vcl/fixed.hxx"
32 : : #include "vcl/dialog.hxx"
33 : : #include "vcl/field.hxx"
34 : :
35 : : #include "svtools/extensionlistbox.hxx"
36 : : #include "svtools/fixedhyper.hxx"
37 : : #include "cppuhelper/implbase1.hxx"
38 : : #include "unotools/collatorwrapper.hxx"
39 : :
40 : : #include "com/sun/star/lang/Locale.hpp"
41 : : #include "com/sun/star/lang/XEventListener.hpp"
42 : : #include "com/sun/star/deployment/XPackage.hpp"
43 : :
44 : : #include <boost/shared_ptr.hpp>
45 : :
46 : : #include "RemoteServer.hxx"
47 : : #include "sdresid.hxx"
48 : :
49 : : namespace sd {
50 : :
51 : : #define SMALL_ICON_SIZE 16
52 : : #define TOP_OFFSET 5
53 : : #define ICON_HEIGHT 42
54 : : #define ICON_WIDTH 47
55 : : #define ICON_OFFSET 72
56 : : #define RIGHT_ICON_OFFSET 5
57 : : #define SPACE_BETWEEN 3
58 : : //------------------------------------------------------------------------------
59 : : // struct ClientBoxEntry
60 : : //------------------------------------------------------------------------------
61 : : struct ClientBoxEntry;
62 : :
63 : : typedef ::boost::shared_ptr< ClientBoxEntry > TClientBoxEntry;
64 : :
65 : : struct ClientBoxEntry
66 : : {
67 : : bool m_bActive :1;
68 : : ClientInfo* m_pClientInfo;
69 : :
70 : :
71 : : ClientBoxEntry( ClientInfo* pClientInfo );
72 : : ~ClientBoxEntry();
73 : :
74 : : };
75 : :
76 : : //------------------------------------------------------------------------------
77 : : // class ExtensionBox_Impl
78 : : //------------------------------------------------------------------------------
79 : :
80 : : class ClientBox;
81 : :
82 : : //------------------------------------------------------------------------------
83 : : class ClientRemovedListener : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
84 : : {
85 : : ClientBox *m_pParent;
86 : :
87 : : public:
88 : :
89 : 0 : ClientRemovedListener( ClientBox *pParent ) { m_pParent = pParent; }
90 : : ~ClientRemovedListener();
91 : :
92 : : //===================================================================================
93 : : // XEventListener
94 : : virtual void SAL_CALL disposing( ::com::sun::star::lang::EventObject const & evt )
95 : : throw (::com::sun::star::uno::RuntimeException);
96 : : };
97 : :
98 : :
99 : : //------------------------------------------------------------------------------
100 : : class ClientBox:
101 : : public Control
102 : : {
103 : : bool m_bHasScrollBar;
104 : : bool m_bHasActive;
105 : : bool m_bNeedsRecalc;
106 : : bool m_bHasNew;
107 : : bool m_bInCheckMode;
108 : : bool m_bAdjustActive;
109 : : bool m_bInDelete;
110 : : //Must be guarded together with m_vEntries to ensure a valid index at all times.
111 : : //Use m_entriesMutex as guard.
112 : : long m_nActive;
113 : : long m_nTopIndex;
114 : : long m_nStdHeight;
115 : : long m_nActiveHeight;
116 : : long m_nExtraHeight;
117 : : Size m_aOutputSize;
118 : : Link m_aClickHdl;
119 : :
120 : : NumericBox m_aPinBox;
121 : : FixedText m_aPinDescription;
122 : :
123 : : ScrollBar* m_pScrollBar;
124 : :
125 : : com::sun::star::uno::Reference< ClientRemovedListener > m_xRemoveListener;
126 : :
127 : : RemoteServer *m_pServer;
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< TClientBoxEntry > m_vEntries;
137 : : std::vector< TClientBoxEntry > m_vRemovedEntries;
138 : :
139 : : CollatorWrapper *m_pCollator;
140 : :
141 : : void CalcActiveHeight( const long nPos );
142 : : long GetTotalHeight() const;
143 : : void SetupScrollBar();
144 : : void DrawRow( const Rectangle& rRect, const TClientBoxEntry pEntry );
145 : : bool HandleTabKey( bool bReverse );
146 : : bool HandleCursorKey( sal_uInt16 nKeyCode );
147 : : void DeleteRemoved();
148 : :
149 : : //-----------------
150 : : DECL_DLLPRIVATE_LINK( ScrollHdl, ScrollBar* );
151 : :
152 : : //Index starts with 1.
153 : : //Throws an com::sun::star::lang::IllegalArgumentException, when the index is invalid.
154 : : void checkIndex(sal_Int32 pos) const;
155 : :
156 : :
157 : : public:
158 : : ClientBox( Dialog* pParent, RemoteServer *pServer,
159 : : const SdResId& aId );
160 : : ~ClientBox();
161 : :
162 : : void MouseButtonDown( const MouseEvent& rMEvt );
163 : : void Paint( const Rectangle &rPaintRect );
164 : : void Resize();
165 : : long Notify( NotifyEvent& rNEvt );
166 : :
167 : : const Size GetMinOutputSizePixel() const;
168 : : void SetExtraSize( long nSize ) { m_nExtraHeight = nSize; }
169 : 0 : TClientBoxEntry GetEntryData( long nPos ) { return m_vEntries[ nPos ]; }
170 : : long GetActiveEntryIndex();
171 : : long GetEntryCount() { return (long) m_vEntries.size(); }
172 : : Rectangle GetEntryRect( const long nPos ) const;
173 : : bool HasActive() { return m_bHasActive; }
174 : : long PointToPos( const Point& rPos );
175 : : void SetScrollHdl( const Link& rLink );
176 : : void DoScroll( long nDelta );
177 : : void SetHyperlinkHdl( const Link& rLink ){ m_aClickHdl = rLink; }
178 : : void RecalcAll();
179 : : void RemoveUnlocked();
180 : :
181 : : //-----------------
182 : : void selectEntry( const long nPos );
183 : : long addEntry( ClientInfo* pClientInfo );
184 : : void updateEntry( const ClientInfo* rPackageInfo );
185 : : void removeEntry( const ClientInfo* rPackageInfo );
186 : :
187 : : void prepareChecking();
188 : : void checkEntries();
189 : :
190 : : OUString getPin();
191 : :
192 : : RemoteServer* getServer() const { return m_pServer; }
193 : : };
194 : :
195 : : }
196 : :
197 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|