/* ** Newton Developer Technical Support Sample Code ** ** SendCard, an example of how to send multiple items to the outbox ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** 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. */ constant kAppSymbol := '|sendCard:PIEDTS|; constant kMyItemIDRoutingSymbol := '|ID:sendCard:PIEDTS|; constant kMyTotalItemsRoutingSymbol := '|total:sendCard:PIEDTS|; // ---- End Project Data ---- // ---- File main.t ---- // Before Script for "myBase" // Written by J. Christopher Bell // Copyright 1993-1994 Apple Computer. All rights reserved. myBase := {viewBounds: {left: 0, top: 46, right: 200, bottom: 154}, appSymbol: kAppSymbol, myRoutingFrame: { // very simple routing frame, just doing beaming beam: { title: "Beam Em!", routeForm: 'zapSlip } }, title: "Send Card", viewSetupDoneScript: func() begin // setup the routing information myCursor := Query(GetUnionSoup(ROM_cardfilesoupname), {type: 'index, indexPath: 'sortOn}) ; // the target data for the route, this would normally be // a cursor Entry. If you want to do mailing, beaming // deleting, ... this MUST be a cursor entry. self.target := myCursor:Entry(); // view that gets the routing messages self.targetView := self ; end, myCursor: nil, viewQuitScript: func() begin myCursor := nil; // you must nil out your cursor in your quit script or else you can // get errors relating to bad reference when you try to take out the card. // errors like this are very difficult to track down, so nil out your cursors! end, SendTheCards: nil, viewFormat: 83951953, SendCards: func() begin local cardArray := []; local entry, index, item; local sendFrame, connectNow; // verify that we are looking at a card OR nil (if no cards present) if myCursor:Entry() = 'deleted then myCursor:Next(); entry := myCursor:Entry(); // get an entry if entry then AddArraySlot(cardArray, entry); entry := myCursor:Next(); // get an entry if entry then AddArraySlot(cardArray, entry); entry := myCursor:Next(); // get an entry if entry then AddArraySlot(cardArray, entry); myCursor:Next(); // move cursor to next name (for next time we are called) /* Note that if there are few cards in the user's Newton, (or the user has * pressed the button multiple times, there could be 0, 1, 2, or 3 items in the cardArray. */ numCards := Length(cardArray); // If we have come the 'end' of the names file. Let the user know... if numCards < 3 or (not myCursor:Entry()) then begin :Notify(kNotifyAlert, EnsureInternal("SendCard"), EnsureInternal("SendCard reached the end of your names file! (Tap ÔSend Three CardsÕ to start over)")); SetValue(mainButton, 'text, "Send Three Cards"); myCursor:Reset(); // start reading names file from top! end; // if there is anything to send... if numCards > 0 then begin foreach index, item in cardArray do begin /* Create the title for the item so the user knows what is being sent. * (remember, if something goes wrong, the user should be able to * understand what data is in her or his inbox/outbox. */ theTitle := "Send Card: " && (index + 1) && "of" && numCards; // If possible, add something to let the user remember which data is contained. if item.sortOn then theTitle := theTitle && "(" &item.sortOn& ")"; if SendTheCards then connectNow := (index = numCards - 1); // connect = true on the last item else connectNow := nil; sendFrame := {appSymbol: 'cardFile, kMyItemIDRoutingSymbol: index, body: item, title: theTitle, connect: connectNow, hidden: nil}; // Send the item asychronously. Even if connect = true, the function will // immediately return. See the Send() documentation in the platforms file docs // for more info. call kSendFunc with ('beam, sendFrame); /* note that you can use the kMyItemIDRoutingSymbol slot to track the incoming * items on the other side. If you 'broke up' the item into many pieces, you can * use this ID to 'put the item' back together. Note that you are going to do this * for multiple items, you might want to put a "unique identifier" (not the uniqueID!) * in the item to distinguish "part 2 of 10 from Big Item One" from * "part 2 of 10 from Big Item Two". * * While this example uses the names app as the receiving application, note that if * you are sending to your own application, you should try to store ALL of your data * within the 'body slot! */ end; end; end, _proto: protoApp, debug: "myBase" }; mainButton := /* child of myBase */ { buttonClickScript: func() begin SetValue(self, 'text, "Send Three More Cards"); :SendCards(); end, text: "Send Three Cards", viewBounds: {left: 0, top: 34, right: 180, bottom: 62}, viewJustify: 22, _proto: protoTextButton, debug: "mainButton" }; // View mainButton is declared to myBase _view000 := /* child of myBase */ {text: "Beam Items Now", viewBounds: {left: 0, top: 80, right: 100, bottom: 96}, valueChanged: func() begin inherited:?ValueChanged(); SendTheCards := viewValue; end, viewSetupDoneScript: func() begin inherited:?viewSetupDoneScript(); :ValueChanged(); // update the SendTheCards value end, viewValue: true, buttonValue: true, viewJustify: 16, _proto: protoCheckbox }; // ---- Beginning of section for non used Layout files ---- // End of output