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