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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svl.hxx" 26 27 #define UNICODE 28 29 #include <string.h> 30 #include "ddeimp.hxx" 31 #include <svl/svdde.hxx> 32 33 // --- DdeInternal::InfCallback() ---------------------------------- 34 35 #ifdef WNT 36 HDDEDATA CALLBACK DdeInternal::InfCallback( 37 WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ) 38 #else 39 #if defined ( MTW ) || ( defined ( GCC ) && defined ( OS2 )) || defined( ICC ) 40 HDDEDATA CALLBACK __EXPORT DdeInternal::InfCallback( 41 WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ) 42 #else 43 HDDEDATA CALLBACK _export DdeInternal::InfCallback( 44 WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ) 45 #endif 46 #endif 47 { 48 return (HDDEDATA)DDE_FNOTPROCESSED; 49 } 50 51 // --- DdeServiceList::DdeServiceList() ---------------------------- 52 53 DdeServiceList::DdeServiceList( const String* pTopic ) 54 { 55 DWORD hDdeInst = NULL; 56 HCONVLIST hConvList = NULL; 57 HCONV hConv = NULL; 58 UINT nStatus = DMLERR_NO_ERROR; 59 HSZ hTopic = NULL; 60 61 #ifndef OS2 // YD FIXME 62 63 nStatus = DdeInitialize( &hDdeInst, (PFNCALLBACK) DdeInternal::InfCallback, 64 APPCLASS_STANDARD | APPCMD_CLIENTONLY | 65 CBF_FAIL_ALLSVRXACTIONS | 66 CBF_SKIP_ALLNOTIFICATIONS, 0L ); 67 68 if ( nStatus == DMLERR_NO_ERROR ) 69 { 70 if ( pTopic ) 71 { 72 LPCTSTR p = reinterpret_cast<LPCTSTR>(pTopic->GetBuffer()); 73 #ifdef __MINGW32__ 74 hTopic = DdeCreateStringHandle( hDdeInst, const_cast<LPTSTR>(p), CP_WINUNICODE ); 75 #else 76 hTopic = DdeCreateStringHandle( hDdeInst, p, CP_WINUNICODE ); 77 #endif 78 } 79 80 hConvList = DdeConnectList( hDdeInst, NULL, hTopic, NULL, NULL ); 81 nStatus = DdeGetLastError( hDdeInst ); 82 } 83 84 if ( nStatus == DMLERR_NO_ERROR ) 85 { 86 while ( ( hConv = DdeQueryNextServer( hConvList, hConv ) ) != NULL) 87 { 88 CONVINFO aInf; 89 TCHAR buf[256], *p; 90 HSZ h; 91 #ifdef OS2 92 aInf.nSize = sizeof( aInf ); 93 #else 94 aInf.cb = sizeof( aInf ); 95 #endif 96 if( DdeQueryConvInfo( hConv, QID_SYNC, &aInf)) 97 { 98 h = aInf.hszServiceReq; 99 if ( !h ) 100 #ifndef OS2 101 h = aInf.hszSvcPartner; 102 #else 103 h = aInf.hszPartner; 104 #endif 105 DdeQueryString( hDdeInst, h, buf, sizeof(buf) / sizeof(TCHAR), CP_WINUNICODE ); 106 p = buf + lstrlen( buf ); 107 *p++ = '|'; *p = 0; 108 DdeQueryString( hDdeInst, aInf.hszTopic, p, sizeof(buf)/sizeof(TCHAR)-lstrlen( buf ), 109 CP_WINUNICODE ); 110 aServices.Insert( new String( reinterpret_cast<const sal_Unicode*>(buf) ) ); 111 } 112 } 113 DdeDisconnectList( hConvList ); 114 } 115 116 if ( hTopic) 117 DdeFreeStringHandle( hDdeInst, hTopic ); 118 if ( hDdeInst ) 119 DdeUninitialize( hDdeInst ); 120 121 #endif 122 123 } 124 125 // --- DdeServiceList::~DdeServiceList() --------------------------- 126 127 DdeServiceList::~DdeServiceList() 128 { 129 String* s; 130 while ( ( s = aServices.First() ) != NULL ) 131 { 132 aServices.Remove( s ); 133 delete s; 134 } 135 } 136 137 // --- DdeTopicList::DdeTopicList() -------------------------------- 138 139 DdeTopicList::DdeTopicList( const String& rService ) 140 { 141 DdeConnection aSys( rService, String( reinterpret_cast<const sal_Unicode*>(SZDDESYS_TOPIC) ) ); 142 143 if ( !aSys.GetError() ) 144 { 145 DdeRequest aReq( aSys, String( reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_TOPICS) ), 500 ); 146 aReq.SetDataHdl( LINK( this, DdeTopicList, Data ) ); 147 aReq.Execute(); 148 } 149 } 150 151 // --- DdeTopicList::~DdeTopicList() ------------------------------- 152 153 DdeTopicList::~DdeTopicList() 154 { 155 String* s; 156 while ( ( s = aTopics.First() ) != NULL ) 157 { 158 aTopics.Remove( s ); 159 delete s; 160 } 161 } 162 163 // --- DdeTopicList::Data() -------------------------------------------- 164 165 IMPL_LINK( DdeTopicList, Data, DdeData*, pData ) 166 { 167 char* p = (char*) (const void *) *pData; 168 char* q = p; 169 short i; 170 char buf[256]; 171 172 while ( *p && *p != '\r' && *p != '\n' ) 173 { 174 q = buf; i = 0; 175 while ( i < 255 && *p && *p != '\r' && *p != '\n' && *p != '\t' ) 176 *q++ = *p++, i++; 177 *q = 0; 178 while ( *p && *p != '\r' && *p != '\n' && *p != '\t' ) 179 p++; 180 aTopics.Insert( new String( String::CreateFromAscii(buf) ) ); 181 if ( *p == '\t' ) 182 p++; 183 } 184 return 0; 185 } 186 187