Update ooo320-m1
[ooovba.git] / svtools / source / svdde / ddeinf.cxx
blobfcdf4e4340f9e52513bd7e7048b02e201c055bc7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ddeinf.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define UNICODE
36 #include <string.h>
37 #include "ddeimp.hxx"
38 #include <svtools/svdde.hxx>
40 // --- DdeInternal::InfCallback() ----------------------------------
42 #ifdef WNT
43 HDDEDATA CALLBACK DdeInternal::InfCallback(
44 WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD )
45 #else
46 #if defined ( MTW ) || ( defined ( GCC ) && defined ( OS2 )) || defined( ICC )
47 HDDEDATA CALLBACK __EXPORT DdeInternal::InfCallback(
48 WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD )
49 #else
50 HDDEDATA CALLBACK _export DdeInternal::InfCallback(
51 WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD )
52 #endif
53 #endif
55 return (HDDEDATA)DDE_FNOTPROCESSED;
58 // --- DdeServiceList::DdeServiceList() ----------------------------
60 DdeServiceList::DdeServiceList( const String* pTopic )
62 DWORD hDdeInst = NULL;
63 HCONVLIST hConvList = NULL;
64 HCONV hConv = NULL;
65 UINT nStatus = DMLERR_NO_ERROR;
66 HSZ hTopic = NULL;
68 #ifndef OS2 // YD FIXME
70 nStatus = DdeInitialize( &hDdeInst, (PFNCALLBACK) DdeInternal::InfCallback,
71 APPCLASS_STANDARD | APPCMD_CLIENTONLY |
72 CBF_FAIL_ALLSVRXACTIONS |
73 CBF_SKIP_ALLNOTIFICATIONS, 0L );
75 if ( nStatus == DMLERR_NO_ERROR )
77 if ( pTopic )
79 LPCTSTR p = reinterpret_cast<LPCTSTR>(pTopic->GetBuffer());
80 #ifdef __MINGW32__
81 hTopic = DdeCreateStringHandle( hDdeInst, const_cast<LPTSTR>(p), CP_WINUNICODE );
82 #else
83 hTopic = DdeCreateStringHandle( hDdeInst, p, CP_WINUNICODE );
84 #endif
87 hConvList = DdeConnectList( hDdeInst, NULL, hTopic, NULL, NULL );
88 nStatus = DdeGetLastError( hDdeInst );
91 if ( nStatus == DMLERR_NO_ERROR )
93 while ( ( hConv = DdeQueryNextServer( hConvList, hConv ) ) != NULL)
95 CONVINFO aInf;
96 TCHAR buf[256], *p;
97 HSZ h;
98 #ifdef OS2
99 aInf.nSize = sizeof( aInf );
100 #else
101 aInf.cb = sizeof( aInf );
102 #endif
103 if( DdeQueryConvInfo( hConv, QID_SYNC, &aInf))
105 h = aInf.hszServiceReq;
106 if ( !h )
107 #ifndef OS2
108 h = aInf.hszSvcPartner;
109 #else
110 h = aInf.hszPartner;
111 #endif
112 DdeQueryString( hDdeInst, h, buf, sizeof(buf) / sizeof(TCHAR), CP_WINUNICODE );
113 p = buf + lstrlen( buf );
114 *p++ = '|'; *p = 0;
115 DdeQueryString( hDdeInst, aInf.hszTopic, p, sizeof(buf)/sizeof(TCHAR)-lstrlen( buf ),
116 CP_WINUNICODE );
117 aServices.Insert( new String( reinterpret_cast<const sal_Unicode*>(buf) ) );
120 DdeDisconnectList( hConvList );
123 if ( hTopic)
124 DdeFreeStringHandle( hDdeInst, hTopic );
125 if ( hDdeInst )
126 DdeUninitialize( hDdeInst );
128 #endif
132 // --- DdeServiceList::~DdeServiceList() ---------------------------
134 DdeServiceList::~DdeServiceList()
136 String* s;
137 while ( ( s = aServices.First() ) != NULL )
139 aServices.Remove( s );
140 delete s;
144 // --- DdeTopicList::DdeTopicList() --------------------------------
146 DdeTopicList::DdeTopicList( const String& rService )
148 DdeConnection aSys( rService, String( reinterpret_cast<const sal_Unicode*>(SZDDESYS_TOPIC) ) );
150 if ( !aSys.GetError() )
152 DdeRequest aReq( aSys, String( reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_TOPICS) ), 500 );
153 aReq.SetDataHdl( LINK( this, DdeTopicList, Data ) );
154 aReq.Execute();
158 // --- DdeTopicList::~DdeTopicList() -------------------------------
160 DdeTopicList::~DdeTopicList()
162 String* s;
163 while ( ( s = aTopics.First() ) != NULL )
165 aTopics.Remove( s );
166 delete s;
170 // --- DdeTopicList::Data() --------------------------------------------
172 IMPL_LINK( DdeTopicList, Data, DdeData*, pData )
174 char* p = (char*) (const void *) *pData;
175 char* q = p;
176 short i;
177 char buf[256];
179 while ( *p && *p != '\r' && *p != '\n' )
181 q = buf; i = 0;
182 while ( i < 255 && *p && *p != '\r' && *p != '\n' && *p != '\t' )
183 *q++ = *p++, i++;
184 *q = 0;
185 while ( *p && *p != '\r' && *p != '\n' && *p != '\t' )
186 p++;
187 aTopics.Insert( new String( String::CreateFromAscii(buf) ) );
188 if ( *p == '\t' )
189 p++;
191 return 0;