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