// Text of project littlePrints written on 5/12/95 at 6:05 PM // Beginning of text file Project Data /* ** Newton Developer Technical Support Sample Code ** ** The Little Prints, A routing example ** ** by Maurice Sharp, Newton Developer Technical Support ** ** Copyright © 1993-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. */ // declare some useful constants constant kBorderFormat := '|borderFormat:littlePrints:PIEDTS| ; // run at application install time // setup stuff the app may need before it is ever opened // or opened for this restart :-) 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().(kBorderFormat) := BuildContext(myApp.myPrintFormat); 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(), kBorderFormat); // End of text file Project Data // Beginning of file myBorderFormat _view000 := { printNextPageScript: func() begin // always print 2 pages worth of stuff // fields.pageNumber is the current page if fields.pageNumber < 3 then begin :RedoChildren() ; true ; end else nil ; end, _proto: @200 }; _view001 := {viewFlags: 1, 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 := {viewFlags: 1, icon: GetPictAsBits("Owl with Drink", nil), viewFormat: nil, viewBounds: {left: 0, top: 0, right: 144, bottom: 166}, viewClass: 76 }; AddStepForm(_view001, _view002); _view003 := {text: "Static Text", viewBounds: {top: 0, left: 0, right: 0, bottom: -20}, viewSetupFormScript: func() begin text := fields.myData.data ; end, viewFont: fancyFont18+tsBold, viewJustify: 246, _proto: @218 }; AddStepForm(_view000, _view003); pageNumber := {text: "Static Text", viewBounds: {top: -20, left: 0, right: 0, bottom: 0}, viewJustify: 8388790, viewSetupFormScript: func() begin text := "Page" && NumberStr(fields.pageNumber) ; end, viewFont: simpleFont18+tsBold, debug: "pageNumber", _proto: @218 }; AddStepForm(_view000, pageNumber); constant |layout_myBorderFormat| := _view000; // End of file myBorderFormat // Beginning of file main.t myBase := {viewBounds: {left: -4, top: 38, right: 200, bottom: 186}, appSymbol: kAppSymbol, myPrintFormat: { // 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: "Little Prints", // 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, // a proto to get a coverPage for free! _proto: ROM_coverPageFormat, // the main format used for each page of // a print or fax output. mainFormat: GetLayout("myBorderFormat"), }, myRoutingFrame: { // very simple routing frame, just doing printing // and faxing // here is the printing stuff, simple yes? print: { title: "Print Thing", routeForm: 'printSlip, formats: [kBorderFormat]}, // and here is the fax stuff fax: { title: "Fax", routeForm: 'faxSlip, formats: [kBorderFormat]}, mail: { title: "Mail", routeForm: 'mailSlip, formats: [kBorderFormat]}, zap: { title: "Beam", routeForm: 'zapSlip}, // a spacer bar spacer1: nil, // and an entry for fun wiggy: { title: "Wig Out!", routeScript: 'wigOutScript} }, SetupRoutingSlip: func(fields) begin // message sent after the user says print or fax // put some information in fields for print, fax // and mail to use. Since fields is available from // print/fax/mail formats, you can add a slot with // relevant info. // NOTE: make the info as small as you can, also // make the info invariant (i.e., do not // just pass a reference to target, since the // the target can change by the time the // print occurs fields.myData := Clone(target) ; // ALSO NOTE: beaming will use the target // slot in your app for the thing beamed. // setup the title that will show in the // outbox item. NOTE: the outbox does not wrap // it will let you overwrite the line below fields.title := title && DateNTime(Time()); end, title: "Little Prints", viewSetupDoneScript: func() begin // setup the routing information // 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 := {data: ""}; // view that gets the routing messages self.targetView := self ; end, wigOutScript: func(target, targetView) begin local oldText := theLine.text ; :SysBeep(); SetValue(theLine, 'text, "Wig Out! Drink Wig Juice (triple espresso)!"); RefreshViews(); theLine:Hilite(true) ; sleep(60) ; theLine:Hilite(nil); SetValue(theLine, 'text, oldText); end, 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. print(item); end, myTextScript: func(fields, target) begin target.data ; // returns the text that will be put into a mail message end, debug: "myBase", _proto: @157 }; theLine := {viewBounds: {left: 8, top: 32, right: 200, bottom: 120}, viewChangedScript: func(slot, view) begin if (slot = 'text) then target.data := text ; end, debug: "theLine", _proto: @185 }; AddStepForm(myBase, theLine); StepDeclare(myBase, theLine, 'theLine); _view004 := {viewJustify: 166, viewBounds: {top: -15, left: -42, right: -25, bottom: -2}, _proto: @209 }; AddStepForm(myBase, _view004); constant |layout_main.t| := myBase; // End of file main.t