xref: /AOO41X/main/svl/inc/svl/svdde.hxx (revision 39a19a47feaddbaa21988da8c7bf801707fd3d48)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SVDDE_HXX
25 #define _SVDDE_HXX
26 
27 #include "svl/svldllapi.h"
28 #include <sot/exchange.hxx>
29 #include <tools/string.hxx>
30 #include <tools/list.hxx>
31 #include <tools/link.hxx>
32 
33 class DdeString;
34 class DdeData;
35 class DdeConnection;
36 class DdeTransaction;
37 class DdeLink;
38 class DdeRequest;
39 class DdeWarmLink;
40 class DdeHotLink;
41 class DdePoke;
42 class DdeExecute;
43 class DdeItem;
44 class DdeTopic;
45 class DdeService;
46 class ConvList;
47 struct DdeDataImp;
48 struct DdeImp;
49 class DdeItemImp;
50 
51 #ifndef _SVDDE_NOLISTS
52 DECLARE_LIST( DdeConnections, DdeConnection* )
53 DECLARE_LIST( DdeServices, DdeService* )
54 DECLARE_LIST( DdeTopics, DdeTopic* )
55 DECLARE_LIST( DdeItems, DdeItem* )
56 #else
57 typedef List DdeConnections;
58 typedef List DdeServices;
59 typedef List DdeTopics;
60 typedef List DdeItems;
61 #endif
62 
63 //#if 0 // _SOLAR__PRIVATE
64 DECLARE_LIST( DdeTransactions, DdeTransaction* )
65 DECLARE_LIST( DdeFormats, long )
66 //#else
67 //typedef List DdeTransactions;
68 //typedef List DdeFormats;
69 //#endif
70 
71 #ifndef STRING_LIST
72 #define STRING_LIST
73 DECLARE_LIST( StringList, String * )
74 #endif
75 
76 // -----------
77 // - DdeData -
78 // -----------
79 
80 class SVL_DLLPUBLIC DdeData
81 {
82     friend class    DdeInternal;
83     friend class    DdeService;
84     friend class    DdeConnection;
85     friend class    DdeTransaction;
86     DdeDataImp*     pImp;
87 
88 //#if 0 // _SOLAR__PRIVATE
89     SVL_DLLPRIVATE void            Lock();
90 //#endif
91     void            SetFormat( sal_uLong nFmt );
92 
93 public:
94                     DdeData();
95                     DdeData( const void*, long, sal_uLong = FORMAT_STRING );
96                     DdeData( const String& );
97                     DdeData( const DdeData& );
98                     ~DdeData();
99 
100     operator const  void*() const;
101     operator        long() const;
102 
103     sal_uLong           GetFormat() const;
104 
105     DdeData&        operator = ( const DdeData& );
106 
107     static sal_uLong GetExternalFormat( sal_uLong nFmt );
108     static sal_uLong GetInternalFormat( sal_uLong nFmt );
109 };
110 // ------------------
111 // - DdeServiceList -
112 // ------------------
113 
114 class DdeServiceList
115 {
116     StringList      aServices;
117 
118 public:
119                     DdeServiceList( const String* = NULL );
120                     ~DdeServiceList();
121 
GetServices()122     StringList&     GetServices() { return aServices; }
123 
124 private:
125                             DdeServiceList( const DdeServiceList& );
126     const DdeServiceList&   operator= ( const DdeServiceList& );
127 };
128 
129 // ----------------
130 // - DdeTopicList -
131 // ----------------
132 
133 class DdeTopicList
134 {
135     StringList      aTopics;
136 
137 //#if 0 // _SOLAR__PRIVATE
138                     DECL_LINK( Data, DdeData* );
139 //#endif
140 public:
141                     DdeTopicList( const String& );
142                     ~DdeTopicList();
143 
GetTopics()144     StringList&     GetTopics() { return aTopics; }
145 };
146 
147 // ------------------
148 // - DdeTransaction -
149 // ------------------
150 
151 class SVL_DLLPUBLIC DdeTransaction
152 {
153 public:
154     virtual void    Data( const DdeData* );
155     virtual void    Done( sal_Bool bDataValid );
156 protected:
157     DdeConnection&  rDde;
158     DdeData         aDdeData;
159     DdeString*      pName;
160     short           nType;
161     long            nId;
162     long            nTime;
163     Link            aData;
164     Link            aDone;
165     sal_Bool            bBusy;
166 
167                     DdeTransaction( DdeConnection&, const String&, long = 0 );
168 
169 public:
170     virtual        ~DdeTransaction();
171 
IsBusy()172     sal_Bool            IsBusy() { return bBusy; }
173     const String&   GetName() const;
174 
175     void            Execute();
176 
SetDataHdl(const Link & rLink)177     void            SetDataHdl( const Link& rLink ) { aData = rLink; }
GetDataHdl() const178     const Link&     GetDataHdl() const { return aData; }
179 
SetDoneHdl(const Link & rLink)180     void            SetDoneHdl( const Link& rLink ) { aDone = rLink; }
GetDoneHdl() const181     const Link&     GetDoneHdl() const { return aDone; }
182 
SetFormat(sal_uLong nFmt)183     void            SetFormat( sal_uLong nFmt ) { aDdeData.SetFormat( nFmt );  }
GetFormat() const184     sal_uLong           GetFormat() const       { return aDdeData.GetFormat(); }
185 
186     long            GetError();
187 
188 private:
189     friend class    DdeInternal;
190     friend class    DdeConnection;
191 
192                             DdeTransaction( const DdeTransaction& );
193     const DdeTransaction&   operator= ( const DdeTransaction& );
194 
195 };
196 
197 // -----------
198 // - DdeLink -
199 // -----------
200 
201 class SVL_DLLPUBLIC DdeLink : public DdeTransaction
202 {
203     Link            aNotify;
204 
205 public:
206                     DdeLink( DdeConnection&, const String&, long = 0 );
207     virtual        ~DdeLink();
208 
SetNotifyHdl(const Link & rLink)209     void            SetNotifyHdl( const Link& rLink ) { aNotify = rLink; }
GetNotifyHdl() const210     const Link&     GetNotifyHdl() const { return aNotify; }
211     virtual void    Notify();
212 };
213 
214 // ---------------
215 // - DdeWarmLink -
216 // ---------------
217 
218 class SVL_DLLPUBLIC DdeWarmLink : public DdeLink
219 {
220 public:
221             DdeWarmLink( DdeConnection&, const String&, long = 0 );
222 };
223 
224 // --------------
225 // - DdeHotLink -
226 // --------------
227 
228 class SVL_DLLPUBLIC DdeHotLink : public DdeLink
229 {
230 public:
231             DdeHotLink( DdeConnection&, const String&, long = 0 );
232 };
233 
234 // --------------
235 // - DdeRequest -
236 // --------------
237 
238 class SVL_DLLPUBLIC DdeRequest : public DdeTransaction
239 {
240 public:
241             DdeRequest( DdeConnection&, const String&, long = 0 );
242 };
243 
244 // -----------
245 // - DdePoke -
246 // -----------
247 
248 class SVL_DLLPUBLIC DdePoke : public DdeTransaction
249 {
250 public:
251             DdePoke( DdeConnection&, const String&, const char*, long,
252                      sal_uLong = FORMAT_STRING, long = 0 );
253             DdePoke( DdeConnection&, const String&, const DdeData&, long = 0 );
254             DdePoke( DdeConnection&, const String&, const String&, long = 0 );
255 };
256 
257 // --------------
258 // - DdeExecute -
259 // --------------
260 
261 class SVL_DLLPUBLIC DdeExecute : public DdeTransaction
262 {
263 public:
264             DdeExecute( DdeConnection&, const String&, long = 0 );
265 };
266 
267 // -----------------
268 // - DdeConnection -
269 // -----------------
270 
271 class SVL_DLLPUBLIC DdeConnection
272 {
273     friend class    DdeInternal;
274     friend class    DdeTransaction;
275     DdeTransactions aTransactions;
276     DdeString*      pService;
277     DdeString*      pTopic;
278     DdeImp*         pImp;
279 
280 public:
281                     DdeConnection( const String&, const String& );
282                     ~DdeConnection();
283 
284     long            GetError();
285     long            GetConvId();
286 
287     static const DdeConnections& GetConnections();
288 
289     sal_Bool            IsConnected();
290 
291     const String&   GetServiceName();
292     const String&   GetTopicName();
293 
294 private:
295                             DdeConnection( const DdeConnection& );
296     const DdeConnection&    operator= ( const DdeConnection& );
297 };
298 
299 // -----------
300 // - DdeItem -
301 // -----------
302 
303 class SVL_DLLPUBLIC DdeItem
304 {
305     friend class    DdeInternal;
306     friend class    DdeTopic;
307     DdeString*      pName;
308     DdeTopic*       pMyTopic;
309     DdeItemImp*     pImpData;
310 
311     void            IncMonitor( sal_uLong );
312     void            DecMonitor( sal_uLong );
313 
314 protected:
315     sal_uInt8            nType;
316 
317 public:
318                     DdeItem( const sal_Unicode* );
319                     DdeItem( const String& );
320                     DdeItem( const DdeItem& );
321                     virtual ~DdeItem();
322 
323     const String&   GetName() const;
324     short           GetLinks();
325     void            NotifyClient();
326 };
327 
328 // -----------
329 // - DdeItem -
330 // -----------
331 
332 class SVL_DLLPUBLIC DdeGetPutItem : public DdeItem
333 {
334 public:
335                     DdeGetPutItem( const sal_Unicode* p );
336                     DdeGetPutItem( const String& rStr );
337                     DdeGetPutItem( const DdeItem& rItem );
338 
339     virtual DdeData* Get( sal_uLong );
340     virtual sal_Bool    Put( const DdeData* );
341     virtual void    AdviseLoop( sal_Bool );     // AdviseLoop starten/stoppen
342 };
343 
344 // ------------
345 // - DdeTopic -
346 // ------------
347 
348 class SVL_DLLPUBLIC DdeTopic
349 {
350     SVL_DLLPRIVATE void _Disconnect( long );
351 
352 public:
353     virtual void    Connect( long );
354     virtual void    Disconnect( long );
355     virtual DdeData* Get( sal_uLong );
356     virtual sal_Bool    Put( const DdeData* );
357     virtual sal_Bool    Execute( const String* );
358         // evt. ein neues anlegen; return 0 -> es konnte nicht angelegt werden
359     virtual sal_Bool MakeItem( const String& rItem );
360 
361         // es wird ein Warm-/Hot-Link eingerichtet. Return-Wert
362         // besagt ob es geklappt hat
363     virtual sal_Bool    StartAdviseLoop();
364     virtual sal_Bool    StopAdviseLoop();
365 
366 private:
367     friend class    DdeInternal;
368     friend class    DdeService;
369     friend class    DdeItem;
370 
371 private:
372     DdeString*      pName;
373     String          aItem;
374     DdeItems        aItems;
375     Link            aConnectLink;
376     Link            aDisconnectLink;
377     Link            aGetLink;
378     Link            aPutLink;
379     Link            aExecLink;
380 
381 public:
382                     DdeTopic( const String& );
383     virtual        ~DdeTopic();
384 
385     const String&   GetName() const;
386     long            GetConvId();
387 
SetConnectHdl(const Link & rLink)388     void            SetConnectHdl( const Link& rLink ) { aConnectLink = rLink; }
GetConnectHdl() const389     const Link&     GetConnectHdl() const { return aConnectLink;  }
SetDisconnectHdl(const Link & rLink)390     void            SetDisconnectHdl( const Link& rLink ) { aDisconnectLink = rLink; }
GetDisconnectHdl() const391     const Link&     GetDisconnectHdl() const { return aDisconnectLink;  }
SetGetHdl(const Link & rLink)392     void            SetGetHdl( const Link& rLink ) { aGetLink = rLink; }
GetGetHdl() const393     const Link&     GetGetHdl() const { return aGetLink;  }
SetPutHdl(const Link & rLink)394     void            SetPutHdl( const Link& rLink ) { aPutLink = rLink; }
GetPutHdl() const395     const Link&     GetPutHdl() const { return aPutLink;  }
SetExecuteHdl(const Link & rLink)396     void            SetExecuteHdl( const Link& rLink ) { aExecLink = rLink; }
GetExecuteHdl() const397     const Link&     GetExecuteHdl() const { return aExecLink; }
398 
399     void            NotifyClient( const String& );
400     sal_Bool            IsSystemTopic();
401 
402     void            InsertItem( DdeItem* );     // fuer eigene Ableitungen!
403     DdeItem*        AddItem( const DdeItem& );  // werden kopiert !
404     void            RemoveItem( const DdeItem& );
GetCurItem()405     const String&   GetCurItem() { return aItem;  }
GetItems()406     const DdeItems& GetItems()   { return aItems; }
407 
408 private:
409                     DdeTopic( const DdeTopic& );
410     const DdeTopic& operator= ( const DdeTopic& );
411 };
412 
413 // --------------
414 // - DdeService -
415 // --------------
416 
417 class SVL_DLLPUBLIC DdeService
418 {
419     friend class    DdeInternal;
420 
421 public:
422     virtual sal_Bool    IsBusy();
423     virtual String  GetHelp();
424         // evt. ein neues anlegen; return 0 -> es konnte nicht angelegt werden
425     virtual sal_Bool    MakeTopic( const String& rItem );
426 
427 protected:
428     virtual String  Topics();
429     virtual String  Formats();
430     virtual String  SysItems();
431     virtual String  Status();
432     virtual String  SysTopicGet( const String& );
433     virtual sal_Bool    SysTopicExecute( const String* );
434 
GetSysTopic() const435     const DdeTopic* GetSysTopic() const { return pSysTopic; }
436 private:
437     DdeTopics       aTopics;
438     DdeFormats      aFormats;
439     DdeTopic*       pSysTopic;
440     DdeString*      pName;
441     ConvList*       pConv;
442     short           nStatus;
443 
444     SVL_DLLPRIVATE sal_Bool            HasCbFormat( sal_uInt16 );
445 
446 public:
447                     DdeService( const String& );
448     virtual        ~DdeService();
449 
450     const String&   GetName() const;
GetError()451     short           GetError()              { return nStatus; }
452 
453     static DdeServices& GetServices();
GetTopics()454     DdeTopics&      GetTopics()             { return aTopics; }
455 
456     void            AddTopic( const DdeTopic& );
457     void            RemoveTopic( const DdeTopic& );
458 
459     void            AddFormat( sal_uLong );
460     void            RemoveFormat( sal_uLong );
461     sal_Bool            HasFormat( sal_uLong );
462 
463 private:
464       //              DdeService( const DdeService& );
465     //int             operator= ( const DdeService& );
466 };
467 
468 // ------------------
469 // - DdeTransaction -
470 // ------------------
471 
GetError()472 inline long DdeTransaction::GetError()
473 {
474     return rDde.GetError();
475 }
476 #endif // _SVDDE_HXX
477