1*40df464eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*40df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*40df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*40df464eSAndrew Rist * distributed with this work for additional information 6*40df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*40df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*40df464eSAndrew Rist * "License"); you may not use this file except in compliance 9*40df464eSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*40df464eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*40df464eSAndrew Rist * software distributed under the License is distributed on an 15*40df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*40df464eSAndrew Rist * KIND, either express or implied. See the License for the 17*40df464eSAndrew Rist * specific language governing permissions and limitations 18*40df464eSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*40df464eSAndrew Rist *************************************************************/ 21*40df464eSAndrew Rist 22*40df464eSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #define UNICODE 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <string.h> 30cdf0e10cSrcweir #include "ddeimp.hxx" 31cdf0e10cSrcweir #include <svl/svdde.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir // --- DdeInternal::InfCallback() ---------------------------------- 34cdf0e10cSrcweir 35cdf0e10cSrcweir #ifdef WNT 36cdf0e10cSrcweir HDDEDATA CALLBACK DdeInternal::InfCallback( 37cdf0e10cSrcweir WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ) 38cdf0e10cSrcweir #else 39cdf0e10cSrcweir #if defined ( MTW ) || ( defined ( GCC ) && defined ( OS2 )) || defined( ICC ) 40cdf0e10cSrcweir HDDEDATA CALLBACK __EXPORT DdeInternal::InfCallback( 41cdf0e10cSrcweir WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ) 42cdf0e10cSrcweir #else 43cdf0e10cSrcweir HDDEDATA CALLBACK _export DdeInternal::InfCallback( 44cdf0e10cSrcweir WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ) 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir #endif 47cdf0e10cSrcweir { 48cdf0e10cSrcweir return (HDDEDATA)DDE_FNOTPROCESSED; 49cdf0e10cSrcweir } 50cdf0e10cSrcweir 51cdf0e10cSrcweir // --- DdeServiceList::DdeServiceList() ---------------------------- 52cdf0e10cSrcweir 53cdf0e10cSrcweir DdeServiceList::DdeServiceList( const String* pTopic ) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir DWORD hDdeInst = NULL; 56cdf0e10cSrcweir HCONVLIST hConvList = NULL; 57cdf0e10cSrcweir HCONV hConv = NULL; 58cdf0e10cSrcweir UINT nStatus = DMLERR_NO_ERROR; 59cdf0e10cSrcweir HSZ hTopic = NULL; 60cdf0e10cSrcweir 61cdf0e10cSrcweir #ifndef OS2 // YD FIXME 62cdf0e10cSrcweir 63cdf0e10cSrcweir nStatus = DdeInitialize( &hDdeInst, (PFNCALLBACK) DdeInternal::InfCallback, 64cdf0e10cSrcweir APPCLASS_STANDARD | APPCMD_CLIENTONLY | 65cdf0e10cSrcweir CBF_FAIL_ALLSVRXACTIONS | 66cdf0e10cSrcweir CBF_SKIP_ALLNOTIFICATIONS, 0L ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir if ( nStatus == DMLERR_NO_ERROR ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir if ( pTopic ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir LPCTSTR p = reinterpret_cast<LPCTSTR>(pTopic->GetBuffer()); 73cdf0e10cSrcweir #ifdef __MINGW32__ 74cdf0e10cSrcweir hTopic = DdeCreateStringHandle( hDdeInst, const_cast<LPTSTR>(p), CP_WINUNICODE ); 75cdf0e10cSrcweir #else 76cdf0e10cSrcweir hTopic = DdeCreateStringHandle( hDdeInst, p, CP_WINUNICODE ); 77cdf0e10cSrcweir #endif 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir hConvList = DdeConnectList( hDdeInst, NULL, hTopic, NULL, NULL ); 81cdf0e10cSrcweir nStatus = DdeGetLastError( hDdeInst ); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir if ( nStatus == DMLERR_NO_ERROR ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir while ( ( hConv = DdeQueryNextServer( hConvList, hConv ) ) != NULL) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir CONVINFO aInf; 89cdf0e10cSrcweir TCHAR buf[256], *p; 90cdf0e10cSrcweir HSZ h; 91cdf0e10cSrcweir #ifdef OS2 92cdf0e10cSrcweir aInf.nSize = sizeof( aInf ); 93cdf0e10cSrcweir #else 94cdf0e10cSrcweir aInf.cb = sizeof( aInf ); 95cdf0e10cSrcweir #endif 96cdf0e10cSrcweir if( DdeQueryConvInfo( hConv, QID_SYNC, &aInf)) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir h = aInf.hszServiceReq; 99cdf0e10cSrcweir if ( !h ) 100cdf0e10cSrcweir #ifndef OS2 101cdf0e10cSrcweir h = aInf.hszSvcPartner; 102cdf0e10cSrcweir #else 103cdf0e10cSrcweir h = aInf.hszPartner; 104cdf0e10cSrcweir #endif 105cdf0e10cSrcweir DdeQueryString( hDdeInst, h, buf, sizeof(buf) / sizeof(TCHAR), CP_WINUNICODE ); 106cdf0e10cSrcweir p = buf + lstrlen( buf ); 107cdf0e10cSrcweir *p++ = '|'; *p = 0; 108cdf0e10cSrcweir DdeQueryString( hDdeInst, aInf.hszTopic, p, sizeof(buf)/sizeof(TCHAR)-lstrlen( buf ), 109cdf0e10cSrcweir CP_WINUNICODE ); 110cdf0e10cSrcweir aServices.Insert( new String( reinterpret_cast<const sal_Unicode*>(buf) ) ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } 113cdf0e10cSrcweir DdeDisconnectList( hConvList ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir if ( hTopic) 117cdf0e10cSrcweir DdeFreeStringHandle( hDdeInst, hTopic ); 118cdf0e10cSrcweir if ( hDdeInst ) 119cdf0e10cSrcweir DdeUninitialize( hDdeInst ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir #endif 122cdf0e10cSrcweir 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir // --- DdeServiceList::~DdeServiceList() --------------------------- 126cdf0e10cSrcweir 127cdf0e10cSrcweir DdeServiceList::~DdeServiceList() 128cdf0e10cSrcweir { 129cdf0e10cSrcweir String* s; 130cdf0e10cSrcweir while ( ( s = aServices.First() ) != NULL ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir aServices.Remove( s ); 133cdf0e10cSrcweir delete s; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir // --- DdeTopicList::DdeTopicList() -------------------------------- 138cdf0e10cSrcweir 139cdf0e10cSrcweir DdeTopicList::DdeTopicList( const String& rService ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir DdeConnection aSys( rService, String( reinterpret_cast<const sal_Unicode*>(SZDDESYS_TOPIC) ) ); 142cdf0e10cSrcweir 143cdf0e10cSrcweir if ( !aSys.GetError() ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir DdeRequest aReq( aSys, String( reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_TOPICS) ), 500 ); 146cdf0e10cSrcweir aReq.SetDataHdl( LINK( this, DdeTopicList, Data ) ); 147cdf0e10cSrcweir aReq.Execute(); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir // --- DdeTopicList::~DdeTopicList() ------------------------------- 152cdf0e10cSrcweir 153cdf0e10cSrcweir DdeTopicList::~DdeTopicList() 154cdf0e10cSrcweir { 155cdf0e10cSrcweir String* s; 156cdf0e10cSrcweir while ( ( s = aTopics.First() ) != NULL ) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir aTopics.Remove( s ); 159cdf0e10cSrcweir delete s; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir // --- DdeTopicList::Data() -------------------------------------------- 164cdf0e10cSrcweir 165cdf0e10cSrcweir IMPL_LINK( DdeTopicList, Data, DdeData*, pData ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir char* p = (char*) (const void *) *pData; 168cdf0e10cSrcweir char* q = p; 169cdf0e10cSrcweir short i; 170cdf0e10cSrcweir char buf[256]; 171cdf0e10cSrcweir 172cdf0e10cSrcweir while ( *p && *p != '\r' && *p != '\n' ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir q = buf; i = 0; 175cdf0e10cSrcweir while ( i < 255 && *p && *p != '\r' && *p != '\n' && *p != '\t' ) 176cdf0e10cSrcweir *q++ = *p++, i++; 177cdf0e10cSrcweir *q = 0; 178cdf0e10cSrcweir while ( *p && *p != '\r' && *p != '\n' && *p != '\t' ) 179cdf0e10cSrcweir p++; 180cdf0e10cSrcweir aTopics.Insert( new String( String::CreateFromAscii(buf) ) ); 181cdf0e10cSrcweir if ( *p == '\t' ) 182cdf0e10cSrcweir p++; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir return 0; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187