// default constants constant kAppSymbol := '|IR Sample:PIEDTS|; constant kAppName := "IR Sample"; // no install or removescripts in this application // ---- End Project Data ---- // ---- File Main.t ---- // Before Script for "IRSample" /* ** Newton Developer Technical Support Sample Code ** ** IR Sample ** ** ** Copyright © 1994 by Apple Computer, Inc. All rights reserved. ** ** You may incorporate this sample code into your applications without ** restriction. This sample code has been provided "AS IS" and the ** responsibility for its operation is 100% yours. You are not ** permitted to modify and redistribute the source as "DTS Sample Code." ** If you are going to re-distribute the source, we require that you ** make it clear in the source that the code was descended from ** Apple-provided sample code, but that you've made changes. */ IRSample := {title: "IR Sample", viewBounds: {left: 0, top: 0, right: 240, bottom: 335}, InitConnection: func(passive) begin SetValue(StatusArea,'text, "Connecting...\n"); RefreshViews(); ep := {_proto: baseEndpoint, _parent: self}; // make a RAM copy so we can modify it local err := ep:Instantiate(ep, nil); if err then begin :Notify(kNotifyAlert, EnsureInternal("IR Sample"), EnsureInternal("Sorry, can't open AppleTalk!")); SetValue(StatusArea, 'text, "Unable to initialize..."); return; end; if passive then err := ep:Listen(nil); else err := ep:Connect(nil, nil); if err then begin :Notify(kNotifyAlert, EnsureInternal("IR Sample"), EnsureInternal("Couldn't connect..." & NumberStr(err))); :PutDataInStatusArea("Unable to connect..."); return; end; ep.myBase := _parent; if passive then :ReadyToReceive(); else :ReadyToSend(); :PutDataInStatusArea("Connected, Waiting for Disconnect..."); connected := true; end, ReleaseConnection: func() begin if (connected) then begin ep.nextInputSpec := nil; // no more input ep:SetInputSpec(nil); // kill the current inputSpec ep:Abort(); // asynchronously abort any pending I/O // must use a delayed action to dispose AddDelayedAction(DisposeConnection, [], 500); end; end, PutDataInStatusArea: func(s) begin SetValue(StatusArea, 'text, s); end, PutDataInReceivedArea: func(s) begin SetValue(ReceivedArea, 'text, s); end, viewSetupDoneScript: func() begin ActiveConnection := 0; ActiveListenConnection := 0; end, SendDataInSendField: func() begin ep:Output(SendDataField.entryLine.text, kFrame + kMore); // frame data, not eom ep:Output(unicodeCR, kFrame); // frame data, eom :ReadyToReceive(); end, Connected: nil, baseEndpoint: { _proto: protoEndpoint, configOptions: [ { label: kCMSSlowIR, type: 'service, opCode: opSetRequired }, ], myBase: nil, exceptionHandler: func(exception) begin if (exception.data <> -16005 and exception.data <> -38001) then GetRoot():Notify(kNotifyAlert, EnsureInternal("IR Sample"), EnsureInternal("Exception: " & exception.data)); return true; end, doInput: { inputForm: 'string, endCharacter: unicodeCR, recvFlags: kFrame, discardAfter: 200, InputScript: func(endpoint, s) begin endpoint.nextInputSpec := nil; // we have finished receiving endpoint:PutDataInStatusArea("Data Received..."); endpoint:PutDataInReceivedArea(s); endpoint:ReadyToSend(); end, }, }, ep: nil, DisposeConnection: func() begin ep:Disconnect(); ep:Dispose(); connected := nil; :PutDataInStatusArea("Ready to connect..."); end, ReadyToSend: func() begin SendButton:Show(); :PutDataInStatusArea("ready to send..."); end, ReadyToReceive: func() begin SendButton:Hide(); // can't send while waiting to receive ep:SetInputSpec(ep.doInput); // set up first inputSpec only for listener :PutDataInStatusArea("waiting for data..."); end, viewSetupFormScript: func() begin local b := GetAppParams(); constant kMaxAppWidth := 240; constant kMaxAppHeight := 336; viewBounds := RelBounds(b.appAreaTop, b.appAreaLeft, MIN(b.AppAreaWidth, kMaxAppWidth), MIN(b.appAreaHeight, kMaxAppHeight)); end, _proto: protoApp, debug: "IRSample" }; _view000 := /* child of IRSample */ {viewFlags: 1, viewFormat: 304, viewBounds: {left: 11, top: 219, right: 233, bottom: 297}, viewclass: 74 }; StatusArea := /* child of IRSample */ {text: "", viewBounds: {left: 10, top: 26, right: 232, bottom: 64}, viewJustify: 0, viewFormat: 67436880, _proto: protoStaticText, debug: "StatusArea" }; // View StatusArea is declared to IRSample ReceivedArea := /* child of IRSample */ {text: "", viewBounds: {left: 10, top: 82, right: 232, bottom: 176}, viewJustify: 0, viewFormat: 67436880, _proto: protoStaticText, debug: "ReceivedArea" }; // View ReceivedArea is declared to IRSample Status := /* child of IRSample */ {text: "Status", viewBounds: {left: 18, top: 18, right: 114, bottom: 34}, viewTransferMode: 0 , _proto: protoStaticText, debug: "Status" }; Received := /* child of IRSample */ {text: "Received Data", viewBounds: {left: 18, top: 74, right: 114, bottom: 90}, viewTransferMode: 0 , _proto: protoStaticText, debug: "Received" }; Connect := /* child of IRSample */ {text: "Connect", buttonClickScript: func() begin if not connected then :InitConnection(nil); // active mode else :Notify(kNotifyAlert, EnsureInternal("IR Sample"), EnsureInternal("already connected!")); end, viewBounds: {left: 12, top: 188, right: 75, bottom: 205}, viewSetupDoneScript: func() begin :PutDataInStatusArea("Ready to Connect..."); end, _proto: protoTextButton, debug: "Connect" }; // View Connect is declared to IRSample Disconnect := /* child of IRSample */ {text: "Disconnect", buttonClickScript: func() begin if connected then begin :PutDataInStatusArea("Disconnecting..."); :ReleaseConnection(); end; else :Notify(kNotifyAlert, EnsureInternal("IR Sample"), EnsureInternal("not connected!")); end, viewBounds: {left: 162, top: 188, right: 233, bottom: 205}, viewQuitScript: func() begin :ReleaseConnection(); end, _proto: protoTextButton, debug: "Disconnect" }; // View Disconnect is declared to IRSample SendDataField := /* child of IRSample */ {viewBounds: {top: 226, left: 18, right: 226, bottom: 290}, viewFormat: 256, viewlinespacing: 16, label: "Data:", textSetup: func() begin return "this is a test"; end, indent: 80, _proto: protoLabelInputLine, debug: "SendDataField" }; // View SendDataField is declared to IRSample SendButton := /* child of IRSample */ {text: "Send", buttonClickScript: func() begin if connected then :SendDataInSendField(); else :Notify(kNotifyAlert, EnsureInternal("IR Sample"), EnsureInternal("not connected!")); end, viewBounds: {left: 78, top: -16, right: 156, bottom: -3}, viewJustify: 8388742, _proto: protoTextButton, debug: "SendButton" }; // View SendButton is declared to IRSample Listen := /* child of IRSample */ {text: "Listen", buttonClickScript: func() begin if not connected then :InitConnection(true); // passive mode else :Notify(kNotifyAlert, EnsureInternal("IR Sample"), EnsureInternal("already connected!")); end, viewBounds: {left: 86, top: 188, right: 149, bottom: 205}, _proto: protoTextButton, debug: "Listen" }; // View Listen is declared to IRSample // ---- Beginning of section for non used Layout files ---- // End of output