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_SVL_SVDDE_HXX
21 #define INCLUDED_SVL_SVDDE_HXX
22
23 #include <sal/config.h>
24
25 #include <svl/svldllapi.h>
26 #include <sot/formats.hxx>
27 #include <rtl/ustring.hxx>
28 #include <tools/solar.h>
29 #include <tools/link.hxx>
30 #include <tools/long.hxx>
31 #include <memory>
32 #include <vector>
33
34 class DdeString;
35 class DdeConnection;
36 class DdeTopic;
37 class DdeService;
38 struct DdeDataImp;
39 struct DdeImp;
40 struct DdeItemImpData;
41 struct Conversation;
42
43 typedef ::std::vector< DdeService* > DdeServices;
44
45
46 class SVL_DLLPUBLIC DdeData
47 {
48 friend class DdeInternal;
49 friend class DdeService;
50 friend class DdeConnection;
51 friend class DdeTransaction;
52 std::unique_ptr<DdeDataImp> xImp;
53
54 SVL_DLLPRIVATE void Lock();
55
56 void SetFormat( SotClipboardFormatId nFmt );
57
58 public:
59 DdeData();
60 DdeData(SAL_UNUSED_PARAMETER const void*, SAL_UNUSED_PARAMETER tools::Long, SAL_UNUSED_PARAMETER SotClipboardFormatId = SotClipboardFormatId::STRING);
61 DdeData(SAL_UNUSED_PARAMETER const OUString&);
62 DdeData(const DdeData&);
63 DdeData(DdeData&&) noexcept;
64 ~DdeData();
65
66 void const * getData() const;
67 tools::Long getSize() const;
68
69 SotClipboardFormatId GetFormat() const;
70
71 DdeData& operator=(const DdeData&);
72 DdeData& operator=(DdeData&&) noexcept;
73
74 static sal_uInt32 GetExternalFormat(SotClipboardFormatId nFmt);
75 static SotClipboardFormatId GetInternalFormat(sal_uLong nFmt);
76 };
77
78
79 class SVL_DLLPUBLIC DdeTransaction
80 {
81 public:
82 void Data( const DdeData* );
83 void Done( bool bDataValid );
84 protected:
85 DdeConnection& rDde;
86 DdeData aDdeData;
87 DdeString* pName;
88 short nType;
89 sal_IntPtr nId;
90 sal_IntPtr nTime;
91 Link<const DdeData*,void> aData;
92 Link<bool,void> aDone;
93 bool bBusy;
94
95 DdeTransaction( DdeConnection&, SAL_UNUSED_PARAMETER const OUString&, SAL_UNUSED_PARAMETER tools::Long = 0 );
96
97 public:
98 virtual ~DdeTransaction();
99
IsBusy() const100 bool IsBusy() const { return bBusy; }
101 OUString GetName() const;
102
103 void Execute();
104
SetDataHdl(const Link<const DdeData *,void> & rLink)105 void SetDataHdl( const Link<const DdeData*,void>& rLink ) { aData = rLink; }
GetDataHdl() const106 const Link<const DdeData*,void>& GetDataHdl() const { return aData; }
107
SetDoneHdl(const Link<bool,void> & rLink)108 void SetDoneHdl( const Link<bool,void>& rLink ) { aDone = rLink; }
GetDoneHdl() const109 const Link<bool,void>& GetDoneHdl() const { return aDone; }
110
SetFormat(SotClipboardFormatId nFmt)111 void SetFormat( SotClipboardFormatId nFmt ) { aDdeData.SetFormat( nFmt ); }
GetFormat() const112 SotClipboardFormatId GetFormat() const { return aDdeData.GetFormat(); }
113
114 tools::Long GetError() const;
115
116 private:
117 friend class DdeInternal;
118 friend class DdeConnection;
119
120 DdeTransaction( const DdeTransaction& ) = delete;
121 const DdeTransaction& operator= ( const DdeTransaction& ) = delete;
122
123 };
124
125
126 class SVL_DLLPUBLIC DdeLink : public DdeTransaction
127 {
128 Link<void*,void> aNotify;
129
130 public:
131 DdeLink( DdeConnection&, const OUString&, tools::Long = 0 );
132 virtual ~DdeLink() override;
133
SetNotifyHdl(const Link<void *,void> & rLink)134 void SetNotifyHdl( const Link<void*,void>& rLink ) { aNotify = rLink; }
GetNotifyHdl() const135 const Link<void*,void>& GetNotifyHdl() const { return aNotify; }
136 void Notify();
137 };
138
139
140 class SVL_DLLPUBLIC DdeHotLink : public DdeLink
141 {
142 public:
143 DdeHotLink( DdeConnection&, const OUString& );
144 };
145
146
147 class SVL_DLLPUBLIC DdeRequest : public DdeTransaction
148 {
149 public:
150 DdeRequest( DdeConnection&, const OUString&, tools::Long = 0 );
151 };
152
153
154 class SVL_DLLPUBLIC DdePoke : public DdeTransaction
155 {
156 public:
157 DdePoke( DdeConnection&, const OUString&, SAL_UNUSED_PARAMETER const DdeData&, tools::Long = 0 );
158 };
159
160
161 class SVL_DLLPUBLIC DdeExecute : public DdeTransaction
162 {
163 public:
164 DdeExecute( DdeConnection&, const OUString&, tools::Long = 0 );
165 };
166
167
168 class SVL_DLLPUBLIC DdeConnection
169 {
170 friend class DdeInternal;
171 friend class DdeTransaction;
172 std::vector<DdeTransaction*> aTransactions;
173 DdeString* pService;
174 DdeString* pTopic;
175 std::unique_ptr<DdeImp> pImp;
176
177 public:
178 DdeConnection( SAL_UNUSED_PARAMETER const OUString&, SAL_UNUSED_PARAMETER const OUString& );
179 ~DdeConnection();
180
181 tools::Long GetError() const;
182
183 static const std::vector<DdeConnection*>& GetConnections();
184
185 bool IsConnected();
186
187 OUString GetServiceName() const;
188 OUString GetTopicName() const;
189
190 private:
191 DdeConnection( const DdeConnection& ) = delete;
192 const DdeConnection& operator= ( const DdeConnection& ) = delete;
193 };
194
195
196 class SVL_DLLPUBLIC DdeItem
197 {
198 friend class DdeInternal;
199 friend class DdeTopic;
200 DdeString* pName;
201 DdeTopic* pMyTopic;
202 std::vector<DdeItemImpData>* pImpData;
203
204 protected:
205 sal_uInt8 nType;
206
207 public:
208 DdeItem( const sal_Unicode* );
209 DdeItem( SAL_UNUSED_PARAMETER const OUString& );
210 DdeItem( const DdeItem& );
211 virtual ~DdeItem();
212
213 OUString GetName() const;
214 short GetLinks();
215 void NotifyClient();
216 };
217
218
219 class SVL_DLLPUBLIC DdeGetPutItem : public DdeItem
220 {
221 public:
222 DdeGetPutItem( const sal_Unicode* p );
223 DdeGetPutItem( const OUString& rStr );
224 DdeGetPutItem( const DdeItem& rItem );
225
226 virtual DdeData* Get( SotClipboardFormatId );
227 virtual bool Put( const DdeData* );
228 virtual void AdviseLoop( bool ); // Start / Stop AdviseLoop
229 };
230
231
232 class SVL_DLLPUBLIC DdeTopic
233 {
234
235 public:
236 virtual DdeData* Get(SotClipboardFormatId);
237 virtual bool Put( const DdeData* );
238 virtual bool Execute( const OUString* );
239 // Eventually create a new item. return 0 -> Item creation failed
240 virtual bool MakeItem( const OUString& rItem );
241
242 // A Warm-/Hot-Link is created. Return true if successful
243 virtual bool StartAdviseLoop();
244
245 private:
246 friend class DdeInternal;
247 friend class DdeService;
248 friend class DdeItem;
249
250 private:
251 DdeString* pName;
252 OUString aItem;
253 std::vector<DdeItem*> aItems;
254
255 public:
256 DdeTopic( SAL_UNUSED_PARAMETER const OUString& );
257 virtual ~DdeTopic();
258
259 OUString GetName() const;
260
261 void NotifyClient( const OUString& );
262 bool IsSystemTopic();
263
264 void InsertItem( DdeItem* ); // For own superclasses
265 DdeItem* AddItem( const DdeItem& ); // Will be cloned
266 void RemoveItem( const DdeItem& );
GetCurItem() const267 const OUString& GetCurItem() const { return aItem; }
GetItems() const268 const std::vector<DdeItem*>& GetItems() const { return aItems; }
269
270 private:
271 DdeTopic( const DdeTopic& ) = delete;
272 const DdeTopic& operator= ( const DdeTopic& ) = delete;
273 };
274
275
276 class SVL_DLLPUBLIC DdeService
277 {
278 friend class DdeInternal;
279
280 protected:
281 OUString Topics();
282 OUString Formats();
283 OUString SysItems();
284 OUString Status();
285
GetSysTopic() const286 const DdeTopic* GetSysTopic() const { return pSysTopic; }
287 private:
288 std::vector<DdeTopic*> aTopics;
289 std::vector< sal_uInt32 > aFormats;
290 DdeTopic* pSysTopic;
291 DdeString* pName;
292 std::vector<std::unique_ptr<Conversation>>
293 m_vConv;
294 short nStatus;
295
296 SVL_DLLPRIVATE bool HasCbFormat( sal_uInt32 );
297
298 public:
299 DdeService( SAL_UNUSED_PARAMETER const OUString& );
300 virtual ~DdeService();
301
302 DdeService( const DdeService& ) = delete;
303 DdeService& operator= ( const DdeService& ) = delete;
304
305 OUString GetName() const;
GetError() const306 short GetError() const { return nStatus; }
307
308 static DdeServices& GetServices();
GetTopics()309 std::vector<DdeTopic*>& GetTopics() { return aTopics; }
310
311 void AddTopic( const DdeTopic& );
312 void RemoveTopic( const DdeTopic& );
313
314 void AddFormat(SotClipboardFormatId);
315 void RemoveFormat(SotClipboardFormatId);
316 bool HasFormat(SotClipboardFormatId);
317 };
318
319
GetError() const320 inline tools::Long DdeTransaction::GetError() const
321 {
322 return rDde.GetError();
323 }
324 #endif // INCLUDED_SVL_SVDDE_HXX
325
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
327