[comp.lang.smalltalk] Smalltalk/V for PM V1.0 bug fixes & enhancements Part 5

cowan@marob.masa.com (John Cowan) (07/27/90)

"

Purpose of DDE-ENH.ST:

Enhancement to DDE facilities.  

Gives access to the DDEAuxWindow facilities used by
the singleRequest and singlePoke class messages for
creating conversations.  The class method initiate:topic:
sets up a client object communicating with an appropriate
server; the client object can then be made to request
or poke data with appropriate messages.

"

! DynamicDataExchange class methods !   
initiate: applicationName topic: topicName
        "Answer a DynamicDataExchange object with attached
        auxiliary window.  The object will be a client of applicationName
        using topic topicName."
    | dde w |
    w := DDEAuxWindow new open.
    dde := self new: w.
    dde window: w.
    dde initiate: applicationName topic: topicName.
    ^dde! !

! DynamicDataExchange class methods !
singlePoke: applicationName topic: topicName item: itemName data: aString
        "Send a single Dynamic Data Exchange poke.
         This initiates a conversation, sends
         the poke, and terminates the conversation."
    | dde |
    dde := self initiate: applicationName topic: topicName.
    dde server notNil ifTrue: [
        dde
            poke: itemName
            data: aString asParameter
            format: DdefmtText].
    dde terminate! !

! DynamicDataExchange class methods !
singleRequest: applicationName topic: topicName item: itemName
        "Make a single Dynamic Data Exchange request and answer the
         result as a String.  This initiates a conversation, sends
         the request, waits for the response, and terminates the
         conversation."
    | dde answer |
    dde := self initiate: applicationName topic: topicName.
    dde server notNil ifTrue: [
        answer := dde getString: itemName format: DdefmtText].
    dde terminate.
    ^answer! !

! DynamicDataExchange methods !   
getByteArray: itemName format: aDdeFormat
        "Get data from the server
         about itemName in aDdeFormat.
         Unlike requestItem:format:, this message
         answers the data returned (as a ByteArray)."
    window isNil ifTrue: [self error: 'No auxiliary window'].
    window byteMode: true.
    data := PMDdeStruct new.
    data format: aDdeFormat.
    data itemName: itemName.
    self post: WmDdeRequest.
    ^window waitForData.! !

! DynamicDataExchange methods ! 
getString: itemName format: aDdeFormat
        "Get data from the server
         about itemName in aDdeFormat.
         Unlike requestItem:format:, this message
         answers the data returned (as a String)."
    window isNil ifTrue: [self error: 'No auxiliary window'].
    window byteMode: false.
    data := PMDdeStruct new.
    data format: aDdeFormat.
    data itemName: itemName.
    self post: WmDdeRequest.
    ^window waitForData.! !

! DynamicDataExchange methods !  
poke: itemName data: someData format: aFormat
        "Poke the server at itemName with someData in aFormat."
    | ddeStruct |
    ddeStruct := PMDdeStruct new
        response: itemName
        data: someData asParameter
        advise: false.
    ddeStruct format: aFormat.
    self poke: ddeStruct.! !

! DynamicDataExchange methods !  
terminate
        "Terminate the exchange."
    data := nil.
    server notNil ifTrue: [self post: WmDdeTerminate].
    window notNil ifTrue: [window close].! !

! DynamicDataExchange methods !   
window
        "Private - Answer the associated DDEAuxWindow,
        or nil if none."
    ^window! !



! DDEAuxWindow methods ! 
byteMode: aBoolean
        "Private - If aBoolean is true, set receiver to return data as a
        ByteArray rather than as a (default) String."
    aBoolean ifTrue: [mode := #data]
        ifFalse: [mode := #dataAsString].! !

! DDEAuxWindow methods !   
ddeData: serverWindow with: aPMDdeStruct
        "Private - DDE data received."
    answer := aPMDdeStruct perform: mode.
    sem wait.
    process notNil ifTrue: [
        Processor resume: process.
        Processor schedule]! !

! DDEAuxWindow methods !  
initialize
        "Private - Initialize the receiver."
    super initialize.
    sem := Semaphore new.
    self byteMode: false.! !


-- 
cowan@marob.masa.com			(aka ...!hombre!marob!cowan)
			e'osai ko sarji la lojban