// Text of project AutoRoute written on 5/12/95 at 5:03 PM // Beginning of text file Project Data /* ** Newton Developer Technical Support Sample Code ** ** Auto Route, more Routing details. ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1995-1995 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 kPrintFormat := '|borderFormat:AutoRoute:PIEDTS|; constant kOtherPrintFormat := '|otherPrintFormat:AutoRoute:PIEDTS|; // run at application install time // setup stuff the app may need before it is ever opened InstallScript := func(partFrame) begin local myApp := partFrame.theForm ; // put my routing frame in the global routing frame routing.(kAppSymbol) := myApp.myRoutingFrame ; // put my format in the root so it can be found GetRoot().(kPrintFormat) := BuildContext(myApp.myPrintFormat); // put my other format in the root so it can be found GetRoot().(kOtherPrintFormat) := BuildContext(myApp.otherPrintFormat); end; // run when application and/or card with app removed // cleanup routing stuff RemoveScript := func(packageFrame) begin // get rid of entry in global routing frame RemoveSlot(routing, kAppSymbol); // remove my print format RemoveSlot(GetRoot(), kPrintFormat); // remove my print format RemoveSlot(GetRoot(), kOtherPrintFormat); end; // End of text file Project Data // Beginning of file myPrintFormat // Before Script for "_view000" // Copyright 1994 Apple Computer, Inc. All rights reserved. _view000 := { printNextPageScript: func() begin // only print one page // returning nil means there are no other pages nil; end, _proto: @200 }; _view001 := {viewFlags: 33, viewFormat: 593, viewBounds: {left: 0, top: 0, right: 0, bottom: 0}, viewSetupFormScript: func() begin self.viewBounds := :Parent():LocalBox() ; self.viewBounds.left := self.viewBounds.left + 2 ; self.viewBounds.right := self.viewBounds.right - 2 ; self.viewBounds.top := self.viewBounds.top + 2 ; self.viewBounds.bottom := self.viewBounds.bottom - 2 ; end, viewClass: 74 }; AddStepForm(_view000, _view001); _view002 := {text: "AutoRoute!......Custom text sent from a Newton far far away...", viewBounds: {top: 30, left: 2, right: -2, bottom: 50}, viewJustify: 50, _proto: @218 }; AddStepForm(_view001, _view002); _view003 := {text: "Static Text", viewBounds: {top: 300, left: 2, right: -2, bottom: 350}, viewSetupFormScript: func() begin // Change our appearance based on the routing data SetValue(self, 'text, fields.body.text); end, viewJustify: 50, viewFormat: 336, _proto: @218 }; AddStepForm(_view001, _view003); constant |layout_myPrintFormat| := _view000; // End of file myPrintFormat // Beginning of file otherPrintFormat // Before Script for "_view004" // Copyright 1994 Apple Computer, Inc. All rights reserved. _view004 := { printNextPageScript: func() begin // only print one page nil; end, _proto: @200 }; _view005 := {viewFlags: 33, viewFormat: 593, viewBounds: {left: 0, top: 0, right: 0, bottom: 0}, viewSetupFormScript: func() begin self.viewBounds := :Parent():LocalBox() ; self.viewBounds.left := self.viewBounds.left + 2 ; self.viewBounds.right := self.viewBounds.right - 2 ; self.viewBounds.top := self.viewBounds.top + 2 ; self.viewBounds.bottom := self.viewBounds.bottom - 2 ; end, viewClass: 74 }; AddStepForm(_view004, _view005); _view006 := { text: "This was done using the other printformat!\nAutoRoute!......Custom text sent from a Newton far far away..." , viewBounds: {top: 30, left: 2, right: -2, bottom: 50}, viewJustify: 50, _proto: @218 }; AddStepForm(_view005, _view006); _view007 := {text: "Static Text", viewBounds: {top: 300, left: 2, right: -2, bottom: 350}, viewSetupFormScript: func() begin // Change our appearance based on the routing data SetValue(self, 'text, fields.body.text); end, viewJustify: 50, viewFormat: 336, _proto: @218 }; AddStepForm(_view005, _view007); constant |layout_otherPrintFormat| := _view004; // End of file otherPrintFormat // Beginning of file myChooser // Before Script for "_view008" // Copyright 1994 Apple Computer, Inc. All rights reserved. _view008 := {viewFlags: 512, viewBounds: {left: 10, top: -27, right: -10, bottom: 39}, viewJustify: 112, declareSelf: 'base, viewFormat: 50398705, viewClass: 74 }; _view009 := {_proto: @166}; AddStepForm(_view008, _view009); _view010 := {viewBounds: {left: 8, top: 14, right: 208, bottom: 46}, viewSetupFormScript: func() begin local toDisplay; //breakloop(); if GetTemporaryPrinterChoice exists then begin // if usedCustomChoice is true, this chooser will // not permanently change userconfiguration.currentPrinter usedCustomChoice := true; originalPrinter := call kGetUserConfigFunc with ('currentPrinter); toDisplay := :GetTemporaryPrinterChoice(); call kSetUserConfigFunc with ('currentPrinter, toDisplay); end; else usedCustomChoice := nil; inherited:?viewSetupFormScript(); end, usedCustomChoice: nil, viewQuitScript: func() begin local theChoice; if usedCustomChoice then begin // assume we need to let someone know what choice was made theChoice := call kGetUserConfigFunc with ('currentPrinter); :SetTemporaryPrinterChoice(theChoice); // restore the current printer to the original choice call kSetUserConfigFunc with ('currentPrinter, originalPrinter); end; // make sure any changes to the user configuration are saved! call kFlushUserConfigFunc with (); inherited:?viewQuitScript(); end, originalPrinter: nil, _proto: @190 }; AddStepForm(_view008, _view010); // After Script for "_view010" thisView := _view010; // Turn this into a real printer chooser button from the ROM thisView._proto := ROM_printerchooserbutton ; constant |layout_myChooser| := _view008; // End of file myChooser // Beginning of file AutoRoute.t // Before Script for "myapp" // Copyright 1994 Apple Computer, Inc. All rights reserved. myapp := { PutAway: func(item) begin // This is the place where you could get wild and move the information // into soups, other apps, and otherwise extract the information. // Note that when you use the auto-email function to send mail, you // must have "self" have a slot called appSymbol so that the mail function // can insert your appsymbol in the outbox item. When the Newton receives // an item which it wants to 'put away', it uses that symbol to actually // know which application to send the item. print("Received the following item:"); print(item); if not GetView(self) then self:Open(); SetValue(para, 'text, item.body.text); end, myCustomText: nil, myRoutingFrame: { // very simple routing frame, just doing printing // and faxing // here is the printing stuff, simple yes? print: { title: "Print Thing", routeForm: 'printSlip, formats: [kPrintFormat, kOtherPrintFormat]}, // and here is the fax stuff fax: { title: "Fax", routeForm: 'faxSlip, formats: [kPrintFormat, kOtherPrintFormat]}, mail: { title: "Mail", routeForm: 'mailSlip, formats: [kPrintFormat, kOtherPrintFormat]}, zap: { title: "Beam", routeForm: 'zapSlip}, }, viewFormat: 83951953, target: "UNUSED TARGET!", hideIOBox: nil, AutoFax: func(sendNow, hideIOBox) begin local myItem, subject; // Do our private setup of 'fields' information. This includes // the phone number to use and the data to send. :SetupMyData(); subject := EnsureInternal("AutoRoute AutoFax: ") && DateNTime(time()); myItem := {connect: sendNow, hidden: hideIOBox, appSymbol: appSymbol, phonenumber: myCustomFrame.toPhone, tophone: "Number to display", title: subject, body: myCustomFrame.myData, name: myCustomFrame.name, printerformat: currentPrintFormat}; call kSendFunc with ('fax, myItem); end, myTextScript: func(fields, target) begin // fields.data ; // returns the text that will be put into a mail message EnsureInternal("This is my text returned by the TextScript!"); end, viewBounds: {left: -1, top: 3, right: 233, bottom: 326}, otherPrintFormat: { // The print format for this application. // An application can have more than one format if it wants. // title that shows up in the Format picker // in the print or fax slip title: "Other Format", // this could be a symbol for an auxilliary // information slip. See the auxForm sample code auxForm: nil, // symbol for a script that is called by // mail for a text only message to send textScript: 'myTextScript, // true if the user can attach a real frame to the mail attachment: true, // The proto must be set to this for all printing and faxing behavior // Note that the actual "cover page" for faxes is controlled by a slot // within the routing 'fields' frame. _proto: ROM_coverPageFormat, // the main format used for each page of a print or fax output. mainFormat: GetLayout("otherPrintFormat"), }, SetTemporaryPrinterChoice: func(theChoice) begin currentPrinterSetting := theChoice; end, myPrintFormat: { // The print format for this application. // An application can ave more than one format if it wants. // title that shows up in the Format picker // in the print or fax slip title: "AutoRoute Format", // this could be a symbol for an auxilliary // information slip. See the auxForm sample code auxForm: nil, // symbol for a script that is called by // mail for a text only message to send textScript: 'myTextScript, // true if the user can attach a real frame to the mail attachment: true, // The proto must be set to this for all printing and faxing behavior // Note that the actual "cover page" for faxes is controlled by a slot // within the routing 'fields' frame. _proto: ROM_coverPageFormat, // the main format used for each page of a print or fax output. mainFormat: GetLayout("myPrintFormat"), }, _proto: @157, myCustomFrame: nil, appSymbol: kAppSymbol, title: "AutoRoute", AutoBeam: func(sendNow, hideIOBox) begin local myItem, subject; subject := EnsureInternal("AutoRoute AutoBeam: ") && DateNTime(time()); // Do our private setup of 'fields' information. This includes // the phone number to use and the data to send. :SetupMyData(); myItem := {connect: sendNow, hidden: hideIOBox, body: myCustomFrame.myData, appSymbol: appSymbol, title: subject }; call kSendFunc with ('beam, myItem); end, SetupMyData: func() begin constant kMyVersionNum := 1; myCustomText := para.text; // since a paragraphView could have 'nil' as its text slot... if not myCustomText then myCustomText := ""; local faxNum := getroot():MungePhone(userconfiguration.faxPhone, userconfiguration.country); // usually, most of these slots will represent the OTHER person's information but we fill // these slots with your own information so that you probably do not have to change any code // to fax or email using this sample. myCustomFrame := TotalClone({toPhone: faxNum, email: userconfiguration.mailAccount, name: "Destination Name/Company", myData: {text: myCustomText, timeStamp: time(), myAppVersion: kMyVersionNum} }); end, currentPrinterSetting: nil, viewSetupFormScript: func() begin local b := GetAppParams(); constant kMaxWidth := 240; constant kMaxHeight := 336; viewBounds := RelBounds(b.appAreaLeft, b.appAreaTop, Min(b.appAreaWidth, kMaxWidth), Min(b.appAreaHeight, kMaxHeight) ); currentPrinterSetting := call kGetUserConfigFunc with ('currentPrinter); currentPrintFormat := kPrintFormat ; end, AutoPrint: func(sendNow, hideIOBox) begin local myItem, subject; :SetupMyData(); subject := EnsureInternal("AutoRoute AutoPrint: ") && DateNTime(time()); myItem := {connect: sendNow, hidden: hideIOBox, appSymbol: appSymbol, body: myCustomFrame.myData, title: subject, printerformat: currentPrintFormat, printer: currentPrinterSetting}; call kSendFunc with ('print, myItem); end, currentPrintFormat: nil, debug: "myapp", AutoEmail: func(sendNow, hideIOBox) begin local subject, myItem; // Do our setup of our custom data for our application :SetupMyData(); subject := EnsureInternal("AutoEmail: " & DateNTime(time())); myItem := {connect: sendNow, hidden: hideIOBox, email: myCustomFrame.email, title: subject, text: myCustomFrame.myData.text, appSymbol: appSymbol, body: myCustomFrame.myData}; call kSendFunc with ('mail, myItem); end, GetTemporaryPrinterChoice: func() begin currentPrinterSetting; end, sendNow: nil }; fax := {text: "Auto-Fax", buttonClickScript: func() begin :AutoFax(sendNow, hideIOBox); end, viewBounds: {left: 0, top: 78, right: 150, bottom: 98}, viewJustify: 8388630, debug: "fax", _proto: @226 }; AddStepForm(myapp, fax); print := {text: "Auto-Print", buttonClickScript: func() begin :AutoPrint(sendNow, hideIOBox); end, viewBounds: {left: 0, top: 108, right: 150, bottom: 128}, viewJustify: 8388630, debug: "print", _proto: @226 }; AddStepForm(myapp, print); email := {text: "Auto-Email", buttonClickScript: func() begin :AutoEmail(sendNow, hideIOBox); end, viewBounds: {left: 0, top: 138, right: 150, bottom: 158}, viewJustify: 8388630, debug: "email", _proto: @226 }; AddStepForm(myapp, email); beam := {text: "Auto-Beam", buttonClickScript: func() begin :AutoBeam(sendNow, hideIOBox); end, viewBounds: {left: 0, top: 168, right: 150, bottom: 188}, viewJustify: 8388630, debug: "beam", _proto: @226 }; AddStepForm(myapp, beam); para := {viewFlags: 7681, viewFormat: 12625, viewLineSpacing: 20, viewFont: 18434, viewBounds: {left: 14, top: 15, right: -6, bottom: 70}, viewJustify: 48, debug: "para", viewClass: 81 }; AddStepForm(myapp, para); StepDeclare(myapp, para, 'para); send now? := {text: "Send/connect now", viewBounds: {left: -32, top: 195, right: 69, bottom: 214}, valueChanged: func() begin sendNow := viewValue; end, buttonValue: true, viewJustify: 8388628, viewValue: true, viewSetupDoneScript: func() begin :valueChanged(); inherited:?viewSetupDoneScript(); end, debug: "send now?", _proto: @164 }; AddStepForm(myapp, send now?); hide iobox? := {text: "Hide outbox", viewBounds: {left: -32, top: 214, right: 69, bottom: 232}, valueChanged: func() begin hideIOBox := viewValue; end, buttonValue: true, viewJustify: 8388628, viewValue: nil, viewSetupDoneScript: func() begin :valueChanged(); inherited:?viewSetupDoneScript(); end, debug: "hide iobox?", _proto: @164 }; AddStepForm(myapp, hide iobox?); _view011 := {text: " ", viewBounds: {left: 139, top: 197, right: 207, bottom: 213}, viewJustify: 8388610, possibleStrings: ["(i/o is busy)", "(idle)"], viewIdleScript: func() begin local index := (if iobusy then 0 else 1); // check the global iobusy variable SetValue(self, 'text, possibleStrings[index]); // This should return the number of milliseconds to delay. NIL if no more idling. 1000; // Check only once a second. // If you check too often, you will run down the battery end, viewSetupDoneScript: func() begin :SetupIdle(1); // after only 1 millisecond, start display end, _proto: @218 }; AddStepForm(myapp, _view011); toPrinter := {text: " ", viewBounds: {left: 87, top: 250, right: 234, bottom: 270}, viewSetupDoneScript: func() begin :SetupIdle(1); // after only 1 millisecond, start display end, viewJustify: 8388610, viewIdleScript: func() begin local name := call kGetPrinterNameFunc with (currentPrinterSetting); SetValue(self, 'text, name); // This should return the number of milliseconds to delay. NIL if no more idling. 1000; // Check only once a second. // If you check too often, you will run down the battery end, debug: "toPrinter", _proto: @218 }; AddStepForm(myapp, toPrinter); StepDeclare(myapp, toPrinter, 'toPrinter); currentPrinter := {text: " ", viewBounds: {left: 19, top: 291, right: 225, bottom: 307}, viewSetupDoneScript: func() begin :SetupIdle(1); // after only 1 millisecond, start display end, viewJustify: 8388610, viewIdleScript: func() begin local printerFrame := call kGetUserConfigFunc with ('currentPrinter); local name := call kGetPrinterNameFunc with (printerFrame); SetValue(self, 'text, "(default:" & name & ")"); // This should return the number of milliseconds to delay. NIL if no more idling. 1000; // Check only once a second. // If you check too often, you will run down the battery end, debug: "currentPrinter", _proto: @218 }; AddStepForm(myapp, currentPrinter); StepDeclare(myapp, currentPrinter, 'currentPrinter); _view012 := {text: "ChangePrinter", buttonClickScript: func() begin printchooser:Open(); end, viewBounds: {top: 252, left: 2, right: 82, bottom: 269}, _proto: @226 }; AddStepForm(myapp, _view012); printchooser := LinkedSubview(_view008, {viewBounds: {left: 6, top: 47, right: 128, bottom: 80}, debug: "printchooser" }); AddStepForm(myapp, printchooser); StepDeclare(myapp, printchooser, 'printchooser); alternate format := {text: "Use Other Print Format", viewBounds: {left: -20, top: 232, right: 106, bottom: 250}, valueChanged: func() begin if viewValue then currentPrintFormat := kOtherPrintFormat ; else currentPrintFormat := kPrintFormat ; end, buttonValue: true, viewJustify: 8388628, viewValue: nil, viewSetupDoneScript: func() begin :valueChanged(); inherited:?viewSetupDoneScript(); end, debug: "alternate format", _proto: @164 }; AddStepForm(myapp, alternate format); constant |layout_AutoRoute.t| := myapp; // End of file AutoRoute.t