summaryrefslogtreecommitdiff
path: root/include/svl/svdde.hxx
blob: e8b808ea1159e4bdc91b12bee6eabde7b4995511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_SVL_SVDDE_HXX
#define INCLUDED_SVL_SVDDE_HXX

#include <sal/config.h>

#include <svl/svldllapi.h>
#include <sot/formats.hxx>
#include <rtl/ustring.hxx>
#include <tools/solar.h>
#include <tools/link.hxx>
#include <tools/long.hxx>
#include <memory>
#include <vector>

class DdeString;
class DdeConnection;
class DdeTopic;
class DdeService;
struct DdeDataImp;
struct DdeImp;
struct DdeItemImpData;
struct Conversation;

typedef ::std::vector< DdeService* > DdeServices;


class SVL_DLLPUBLIC DdeData
{
    friend class    DdeInternal;
    friend class    DdeService;
    friend class    DdeConnection;
    friend class    DdeTransaction;
    std::unique_ptr<DdeDataImp>    xImp;

    SVL_DLLPRIVATE void            Lock();

    void            SetFormat( SotClipboardFormatId nFmt );

public:
                    DdeData();
                    DdeData(SAL_UNUSED_PARAMETER const void*, SAL_UNUSED_PARAMETER tools::Long, SAL_UNUSED_PARAMETER SotClipboardFormatId = SotClipboardFormatId::STRING);
                    DdeData(SAL_UNUSED_PARAMETER const OUString&);
                    DdeData(const DdeData&);
                    DdeData(DdeData&&) noexcept;
                    ~DdeData();

    void const *    getData() const;
    tools::Long            getSize() const;

    SotClipboardFormatId GetFormat() const;

    DdeData&        operator=(const DdeData&);
    DdeData&        operator=(DdeData&&) noexcept;

    static sal_uInt32 GetExternalFormat(SotClipboardFormatId nFmt);
    static SotClipboardFormatId GetInternalFormat(sal_uLong nFmt);
};


class SVL_DLLPUBLIC DdeTransaction
{
public:
    void    Data( const DdeData* );
    void    Done( bool bDataValid );
protected:
    DdeConnection&  rDde;
    DdeData         aDdeData;
    DdeString*      pName;
    short           nType;
    sal_IntPtr      nId;
    sal_IntPtr      nTime;
    Link<const DdeData*,void> aData;
    Link<bool,void>           aDone;
    bool            bBusy;

                    DdeTransaction( DdeConnection&, SAL_UNUSED_PARAMETER const OUString&, SAL_UNUSED_PARAMETER tools::Long = 0 );

public:
    virtual        ~DdeTransaction();

    bool            IsBusy() const { return bBusy; }
    OUString GetName() const;

    void            Execute();

    void            SetDataHdl( const Link<const DdeData*,void>& rLink ) { aData = rLink; }
    const Link<const DdeData*,void>& GetDataHdl() const { return aData; }

    void            SetDoneHdl( const Link<bool,void>& rLink ) { aDone = rLink; }
    const Link<bool,void>& GetDoneHdl() const { return aDone; }

    void                 SetFormat( SotClipboardFormatId nFmt ) { aDdeData.SetFormat( nFmt );  }
    SotClipboardFormatId GetFormat() const       { return aDdeData.GetFormat(); }

    tools::Long            GetError() const;

private:
    friend class    DdeInternal;
    friend class    DdeConnection;

                            DdeTransaction( const DdeTransaction& ) = delete;
    const DdeTransaction&   operator= ( const DdeTransaction& ) = delete;

};


class SVL_DLLPUBLIC DdeLink : public DdeTransaction
{
    Link<void*,void> aNotify;

public:
                    DdeLink( DdeConnection&, const OUString&, tools::Long = 0 );
    virtual        ~DdeLink() override;

    void            SetNotifyHdl( const Link<void*,void>& rLink ) { aNotify = rLink; }
    const Link<void*,void>&   GetNotifyHdl() const { return aNotify; }
    void    Notify();
};


class SVL_DLLPUBLIC DdeHotLink : public DdeLink
{
public:
            DdeHotLink( DdeConnection&, const OUString& );
};


class SVL_DLLPUBLIC DdeRequest : public DdeTransaction
{
public:
            DdeRequest( DdeConnection&, const OUString&, tools::Long = 0 );
};


class SVL_DLLPUBLIC DdePoke : public DdeTransaction
{
public:
            DdePoke( DdeConnection&, const OUString&, SAL_UNUSED_PARAMETER const DdeData&, tools::Long = 0 );
};


class SVL_DLLPUBLIC DdeExecute : public DdeTransaction
{
public:
            DdeExecute( DdeConnection&, const OUString&, tools::Long = 0 );
};


class SVL_DLLPUBLIC DdeConnection
{
    friend class    DdeInternal;
    friend class    DdeTransaction;
    std::vector<DdeTransaction*> aTransactions;
    DdeString*      pService;
    DdeString*      pTopic;
    std::unique_ptr<DdeImp> pImp;

public:
                    DdeConnection( SAL_UNUSED_PARAMETER const OUString&, SAL_UNUSED_PARAMETER const OUString& );
                    ~DdeConnection();

    tools::Long            GetError() const;

    static const std::vector<DdeConnection*>& GetConnections();

    bool            IsConnected();

    OUString        GetServiceName() const;
    OUString        GetTopicName() const;

private:
                            DdeConnection( const DdeConnection& ) = delete;
    const DdeConnection&    operator= ( const DdeConnection& ) = delete;
};


class SVL_DLLPUBLIC DdeItem
{
    friend class    DdeInternal;
    friend class    DdeTopic;
    DdeString*      pName;
    DdeTopic*       pMyTopic;
    std::vector<DdeItemImpData>* pImpData;

protected:
    sal_uInt8            nType;

public:
                    DdeItem( const sal_Unicode* );
                    DdeItem( SAL_UNUSED_PARAMETER const OUString& );
                    DdeItem( const DdeItem& );
                    virtual ~DdeItem();

    OUString GetName() const;
    short           GetLinks();
    void            NotifyClient();
};


class SVL_DLLPUBLIC DdeGetPutItem : public DdeItem
{
public:
                    DdeGetPutItem( const sal_Unicode* p );
                    DdeGetPutItem( const OUString& rStr );
                    DdeGetPutItem( const DdeItem& rItem );

    virtual DdeData* Get( SotClipboardFormatId );
    virtual bool    Put( const DdeData* );
    virtual void    AdviseLoop( bool );     // Start / Stop AdviseLoop
};


class SVL_DLLPUBLIC DdeTopic
{

public:
    virtual DdeData* Get(SotClipboardFormatId);
    virtual bool Put( const DdeData* );
    virtual bool Execute( const OUString* );
    // Eventually create a new item. return 0 -> Item creation failed
    virtual bool MakeItem( const OUString& rItem );

    // A Warm-/Hot-Link is created. Return true if successful
    virtual bool    StartAdviseLoop();

private:
    friend class    DdeInternal;
    friend class    DdeService;
    friend class    DdeItem;

private:
    DdeString*            pName;
    OUString              aItem;
    std::vector<DdeItem*> aItems;

public:
                    DdeTopic( SAL_UNUSED_PARAMETER const OUString& );
    virtual        ~DdeTopic();

    OUString        GetName() const;

    void            NotifyClient( const OUString& );
    bool            IsSystemTopic();

    void            InsertItem( DdeItem* );     // For own superclasses
    DdeItem*        AddItem( const DdeItem& );  // Will be cloned
    void            RemoveItem( const DdeItem& );
    const OUString& GetCurItem() const { return aItem;  }
    const std::vector<DdeItem*>& GetItems() const  { return aItems; }

private:
                    DdeTopic( const DdeTopic& ) = delete;
    const DdeTopic& operator= ( const DdeTopic& ) = delete;
};


class SVL_DLLPUBLIC DdeService
{
    friend class    DdeInternal;

protected:
    OUString Topics();
    OUString Formats();
    OUString SysItems();
    OUString Status();

    const DdeTopic* GetSysTopic() const { return pSysTopic; }
private:
    std::vector<DdeTopic*> aTopics;
    std::vector< sal_uInt32 > aFormats;
    DdeTopic*       pSysTopic;
    DdeString*      pName;
    std::vector<std::unique_ptr<Conversation>>
                    m_vConv;
    short           nStatus;

    SVL_DLLPRIVATE bool HasCbFormat( sal_uInt32 );

public:
                    DdeService( SAL_UNUSED_PARAMETER const OUString& );
    virtual        ~DdeService();

                    DdeService( const DdeService& ) = delete;
    DdeService&     operator= ( const DdeService& ) = delete;

    OUString        GetName() const;
    short           GetError() const { return nStatus; }

    static DdeServices& GetServices();
    std::vector<DdeTopic*>& GetTopics() { return aTopics; }

    void            AddTopic( const DdeTopic& );
    void            RemoveTopic( const DdeTopic& );

    void            AddFormat(SotClipboardFormatId);
    void            RemoveFormat(SotClipboardFormatId);
    bool            HasFormat(SotClipboardFormatId);
};


inline tools::Long DdeTransaction::GetError() const
{
    return rDde.GetError();
}
#endif // INCLUDED_SVL_SVDDE_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */