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