// Text of project VariRoute written on 7/8/97 at 4:11 PM // Beginning of text file Constants /* ** Newton Developer Technical Support Sample Code ** ** VariRoute, a Newton 2.0 routing example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-7 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 kMySimpleVariableSizeViewClass := '|simplevari:VariRoute:DTS|; constant kMyEditViewDataClass := '|editview:VariRoute:DTS|; constant kMyBigTextViewClass := '|bigtext:VariRoute:DTS|; constant kSimpleVariViewDefSym := '|simpleVariViewDef:VariRoute:DTS| ; constant kEditViewViewDefSym := '|editViewViewDef:VariRoute:DTS| ; constant kBigTextViewDefSym := '|bigTextViewDef:VariRoute:DTS| ; // Get the cup icon OpenResFile(home & "pictures"); DefConst('kCupIcon, GetPictAsBits("minRouteIcon", nil)); CloseResFile(); // This is a clEditView template from the paperroll. This is here so this sample can do a demo printout of // complex clEditView data without requiring the user to write in anything. For YOUR application, you'd // get this kind of data from the viewChildren slot of a real clEditView. This flattened frame listed below // looks like {data: [firstKid, secondKid, thirdKid...] ... } DefConst('kFlattenedEditViewChildren, MakeBinaryFromHex( "0206080705636C617373070464617461070E7669657753746174696F6E657279070668656967687407085F76657273696F6E070974696D657374616D7007095F756E69717565494407085F6D6F6454696D6507097061706572726F6C6C05130604070A76696577426F756E64730903070474657874070876696577466F6E74060407046C6566740703746F70070572696768740706626F74746F6D0038008C00FF000004FC00FF000003F407047061726108FF000001F4004800610076006500200079006F00750020006500760065007200200077006F006E0064006500720065006400200068006F00770020007200650061006C006C0079002000760069 00650077007300200061007200650020007000720069006E007400650064002000660072006F006D00200074006800650020004E006F0074006500730020006100700070006C00690063006100740069006F006E003F0020004E006F0074006500200074006800610074002000740068006900730020007000610072006100670072006100700068002000690073002000770072006100700070006500640020006100740020007400680065002000660075006C006C0020007700690064007400680020006F0066002000740068006500200070006100670065002E002000540068006100740020006900730020006200650063006100750073006500200074 00680065007200650020006900730020006E006F0020006F0074006800650072002000740065007800740020006F0072002000670072006100700068006900630073002000740068006100740020006D006900670068007400200073007500670067006500730074002000690074002000690073002000700061007200740020006F00660020006100200073006B00650074006300680020006F0072002000670072006F00750070002E000000FF0001200C0605090C0903090D090E070974657874466C61677306040910091109120913005400FF0000087C00FF000003AC00FF00000B04091408FF0000010000540068006900730020007000610072006100 6700720061007000680020006900730020006C006F006E006700200065006E006F0075006700680020007400680061007400200069007400200063006F0075006C006400200062006500200063006F006E00730069006400650072006500640020006A0075007300740020006100200062006900670020007000610072006100670072006100700068002E00200048006F00770065007600650072002C00200069007400200069007300200074006F006F00200063006C006F0073006500200074006F0020007400680069007300200020006F007400680065007200200076006900650077002E002E002E000000FF0001200C00000605090C09170903090D09 0E06040910091109120913007400FF0000050400FF000004E400FF000006AC0000091408F20054006800690073002000700061007200610067007200610070006800200069007300200063006C006F0073006500200074006F0020006F0074006800650072002000760069006500770073002E00200053006F00200074006800650020005200650066006C006F0077002000660075006E006300740069006F006E00200063006F006E007300690064006500720073002000690074002000700061007200740020006F0066002000670072006F0075007000200061006E006400200064006F006500730020006E006F00740020006300680061006E0067006500 20007400680065002000770069006400740068002E000000FF0001200C0603090C09030706706F696E74730604091209110910091300FF000004D000FF000004E8004800FF000006E40704706F6C790318070C706F6C79676F6E7368617065000B000500000000007F0000007F012200000122000000000604070B6172636572626F756E6473090C0903091E0B0000271D0604091209110910091300FF0000049C00FF0000069000FF0000042800FF0000072C092003680922000000190014001D000F001D0009001B0005001900020016000000120000000E0000000B000200070005000400090002000F00000014000000180000001E000200220004002400 070027000B0027000F002700120024001600220019001E001B0018001D0014001D06040924090C0903091E0B0000271D0604091209110910091300DC00FF00000690006800FF0000072C092003680922000000190014001D000F001D0009001B0005001900020016000000120000000E0000000B000200070005000400090002000F00000014000000180000001E000200220004002400070027000B0027000F002700120024001600220019001E001B0018001D0014001D06040924090C0903091E0B00001E160604091209110910091300FF0000049000FF000004A800FF0000043800FF0000052009200368092200000019000F0016000B00150008001400 040012000100100000000D0000000A00000008000100050004000300080001000B0000000F00000013000000170001001A0003001C0005001E0008001E000B001E000D001C0010001A00120017001400130015000F001606040924090C0903091E0B00001E160604091209110910091300D000FF000004A8007800FF0000052009200368092200000019000F0016000B00150008001400040012000100100000000D0000000A00000008000100050004000300080001000B0000000F00000013000000170001001A0003001C0005001E0008001E000B001E000D001C0010001A00120017001400130015000F00160602090C0703696E6B060409120911091009 1300FF0000026C00FF00000C2400FF0000017800FF00000EF8032F0704696E6B3258020249B17C04BF375F5B84329CEB4C84DE913621A1CC7E212F3F060C924EBD5A1D0118EFAE73277F7194BB610D100602090C09350604091209110910091300FF0000017400FF00000C7000A400FF00000CB4031009385802080742256F36C83B1E9A811106020602090C09350604091209110910091300FF000001AC00FF00000D04009C00FF00000D5403100938580212DD3541193F159BA1CCC64AD0200602090C09350604091209110910091300FF000001A000FF00000DB0009400FF00000DF40313093858020F87E0213960BC9D4249289C91E1690C010604090C09 03090D090E0604091009110912091300FF0000028000FF00000DAC00FF0000046000FF00000E040914081C00530061006E0020004600720061006E0063006900730063006F000000FF0001200C0604090C0903090D090E0604091009110912091300FF0000026C00FF00000BDC00FF0000033C00FF00000C340914080C004D006100720069006E000000FF0001200C0602090C09350604091209110910091300FF0000026800FF00000C0C00FF000001B400FF00000C980310093858051D5D4082CA946FC4A652207D5F870602090C09350604091209110910091300FF0000026800FF00000D8800FF000001D400FF00000DFC0312093858231A0F12E3D196EC CCC19E3B322E3329040604090C0903090D090E0604091009110912091300FF0000025C00FF00000C9C00FF0000040400FF00000D640914082C004200650072006B0065006C006500790020000D0061006E00640020004F0061006B006C0061006E0064000000FF0001200C0604090C0903090D090E06040910091109120913003000FF0000104C00FF0000050000FF00001504091408FF000002A8004E006F0074006500200074006800610074002000740068006900730020007000610072006100670072006100700068002000690073002000770072006100700070006500640020006100740020007400680065002000660075006C006C00200077006900 64007400680020006F0066002000740068006500200070006100670065002E00200054006800610074002000690073002000620065006300610075007300650020007400680065007200650020006900730020006E006F0020006F0074006800650072002000740065007800740020006F0072002000670072006100700068006900630073002000740068006100740020006D006900670068007400200073007500670067006500730074002000690074002000690073002000700061007200740020006F00660020006100200073006B00650074006300680020006F0072002000670072006F00750070002E0020004E006F00740065002000740068006100 74002000740068006900730020007000610072006100670072006100700068002000690073002000770072006100700070006500640020006100740020007400680065002000660075006C006C0020007700690064007400680020006F0066002000740068006500200070006100670065002E00200054006800610074002000690073002000620065006300610075007300650020007400680065007200650020006900730020006E006F0020006F0074006800650072002000740065007800740020006F0072002000670072006100700068006900630073002000740068006100740020006D00690067006800740020007300750067006700650073007400 2000690074002000690073002000700061007200740020006F00660020006100200073006B00650074006300680020006F0072002000670072006F00750070002E000000FF0001200C060407067374796C6573090D090C090305060004033E0707696E6B576F7264580C18D3BC0A510029CB718679F159D1D14900095110ACA404B2774B5C0AD2341E7046CF2C29592920E94343564638A7F8B173C90DAC1A42901104003000000400FF0001200C0004032B095858021903034D16508924E2249F839E3D4CCB0B1F2BE5A895383959F89B400B88BD03081141900902C030000808F7010020F70100000604091009110912091300FF0000026C00FF00000A4400 FF000004AC00FF00000ADC0914090900FF00001560000800FF0BB8FCE4000000FF0BB99C24", 'binary)); constant kAboutString := "VariRoute is Newton DTS Sample Code. This sample shows how to layout and print items with varying heights, using three different types of data and corresponding techniques.."; constant kHelpString := "Click on one of the data types and then tap the Action/Routing button."; constant kMyIndent := 10; // used by the PrintSimpleVari layout constant kBigText1 := "Lorem ipsum dolor sit amet, consectetuer adipisceing elit, sud diam noneummy nibh euismod timcidunt ut laoreet dolore magna aoiquam erat polutpat. Ut wisi enim ad minim penaim, quis nostrud exerci tation ullancorter suscipit lobortis nis, ut aliquip."; constant kBigText2 := "Ea commodo consequat. Duis autem pel erm iriure dolor im hendrerit in pulputate pelit esse molestie consequat pel illum."; constant kVeryLongText := "Lorem ipsum dolor sit amet, consectetuer adipisceing elit, sud diam noneummy nibh euismod timcidunt ut laoreet dolore magna aoiquam erat polutpat. Ut wisi enim ad minim penaim, quis nostrud exerci tation ullancorter suscipit lobortis nis, ut aliquip. Ea commodo consequat. Duis autem pel erm iriure dolor im hendrerit in pulputate pelit esse molestie consequat pel illum. Dolore eu feugait nulla facalisis at vero eros et accumsan at iusto odio dignissim qui blandit traesent luptatum zzril plenit augue dois dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipisceing elit, sud diam noneummy nibh euismod timcidunt ut laoreet dolore magna aoiquam erat polutpat. Ut wisi enim ad minim penaim, quis nostrud exerci tation ullancorter suscipit lobortis nis, ut aliquip ex ea commodo consequat. Duis autem pel erm iriure dolor im hendrerit in pulputate pelit esse molestie consequat pel illum dolore eu feugait nulla. Facalisis at vero eros et accumsan at iusto odio dignissim qui blandit traesent luptatum zzril plenit augue dois dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipisceing elit, sud diam noneummy nibh euismod timcidunt ut laoreet dolore magna aoiquam erat polutpat. Ut wisi enim ad minim penaim. Ea commodo consequat. Duis autem pel erm iriure dolor im hendrerit in pulputate pelit esse molestie consequat pel illum. Dolore eu feugait nulla facalisis at vero eros et accumsan at iusto odio dignissim qui blandit traesent luptatum zzril plenit augue dois dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipisceing elit, sud diam noneummy nibh euismod timcidunt ut laoreet dolore magna aoiquam erat polutpat. Ut wisi enim ad minim penaim, quis nostrud exerci tation ullancorter suscipit lobortis nis, ut aliquip ex ea commodo consequat. Duis autem pel erm iriure dolor im hendrerit in pulputate pelit esse molestie consequat pel illum dolore eu feugait nulla. Facalisis at vero eros et accumsan at iusto odio dignissim qui blandit traesent luptatum zzril plenit augue dois dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipisceing elit, sud diam noneummy nibh euismod timcidunt ut laoreet dolore magna aoiquam erat polutpat. Ut wisi enim ad minim penaim. "; // End of text file Constants // Beginning of text file kReflowWrapperFunc /* ** Newton Developer Technical Support Sample Code ** ** VariRoute, a Newton 2.0 routing example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-7 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. */ // kReflowWrapperFunc // // This is a wrapper function for using the Reflow function, which prepares and groups // clEditView view templates for intelligent printing. It tries to keep graphics and 'clustered' // objects together. // // Arguments: // stepChildren: an array of clEditView view templates // fontSpec: the font to be used for printing. If nil, the default font will be used // box: the local coordinates of the destination view // // kReflowWrapperFunc returns an array of view templates (which may be different in number // from the original because of grouping), that may contain slightly different values for viewFlags, // viewJustify, and viewBounds slots. // // Note that there are some arguments to Reflow(...) that must be specific // values, and they are provided in this wrapper function. // // *** See the README.VariRoute file for more information on how to use it! *** DefineGlobalConstant('kReflowWrapperFunc, func(editViewChildren, fontSpec, box) begin local reflowOptions := { unistyle: nil, // this should always be this value. Do not change it. graphicsGutter: 16, // this should always be this value. Do not change it. textGutter: -16, // this should always be this value. Do not change it. viewLineSpacing: 30 // this should always be this value. Do not change it. }; if fontSpec then reflowOptions.reflowFont := fontSpec; Reflow(editViewChildren, reflowOptions, RelBounds(0,0,0,0), box); end); // End of text file kReflowWrapperFunc // Beginning of file PrintSimpleVari // Before Script for "_view000" /* ** Newton Developer Technical Support Sample Code ** ** VariRoute, a Newton 2.0 routing example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-7 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. */ _view000 := { printNextPageScript: func() begin // If there are still views to print, then we do RedoChildren and return true, if printFormatKids and Length(printFormatKids) > reflowStart then begin // we check this in viewSetupFormScript to distinguish between // Initialization and RedoChildren; myPageCounter := myPageCounter + 1; :RedoChildren(); // rebuild all our views in preparation for the next page true; // return true to indicate "there are more pages" end; // ...else implicitly return nil to indicate "no more pages" end, symbol: kSimpleVariViewDefSym, viewSetupFormScript: func() begin myPageCounter := 1; // don't rely on fields.pageNumber to track pages! We track it // and increment it in printNextPageScript self.reflowStart := 0; // Used when using kReflowWrapperFunc inherited:?viewSetupFormScript(); // this method is defined internally end, formatInitScript: func(fields,theTarget) begin /* If you need to do prep something which takes a long time, and you are * worried about "timing out" a fax machine, do it here, not * in viewSetupFormScript!!! */ end, SetupItem: func(item, tInfo) begin /* If you have any "preprocessing" to do like set anything in the item or add * extra slots like version slots, or extra data, you can do it here, but if you are * trying to actually prep the visual shapes, you should do that in formatInitScript. */ inherited:?SetupItem(item, tInfo); // set the title; note that the string will be editable by the user... item.title := "VariRoute item: " & datentime(time()); item; end, title: "MyFormat", myPageCounter: nil, printFormatKids: nil // This is set in the notesView to be the array of Reflow-ed view templates , _proto: @200 }; indented frame := {viewBounds: {left: 10, top: 10, right: -10, bottom: -10}, viewFlags: 1, viewFormat: 593, viewJustify: 240, viewClass: 74 }; AddStepForm(_view000, indented frame); // Before Script for "NotesView" DefConst('kMySimpleVariProto, // A simple variable-size view { viewClass: clParagraphView, viewBounds: SetBounds(60,kMyIndent,-60,kMyIndent + 20), viewfont: simpleFont10, viewJustify:vjParentFullH+vjSiblingBottomV, viewformat: vfPen(1) + vfFrameBlack, viewflags: vVisible, text: nil, sizeMultiplier: 1, // this variable will change for each one... number: nil, // this variable will change for each one... viewSetupFormScript: func() begin if sizeMultiplier > 1 then begin viewBounds := clone(viewBounds); viewBounds.bottom := kMyIndent + 20 * sizeMultiplier; end; // it will say something like "View #4 has sizeMultiplier 2"; text := "View #" && number && "has sizeMultiplier" && sizeMultiplier; end; }); DefConst('kMySelfSizingPara, // A variable-size paragraph view { viewclass: clParagraphView, viewBounds: SetBounds(0,0,0,0), viewfont: simpleFont10, viewJustify:vjParentFullH+vjSiblingBottomV, viewformat: vfNone, viewflags: vVisible, text: nil, viewSetupFormScript: func() begin // Assumes viewJustify=vjParentFullH+vjSiblingBottomV and viewBounds=SetBounds(0,0,0,0), local rect := { left:0, right: self:LocalBox().right, top:0, bottom:0 }; TextBounds(text, {font: viewFont}, rect); viewBounds := Clone(viewBounds); viewBounds.bottom := rect.bottom + kMyIndent; viewBounds.top := viewBounds.top + kMyIndent; end; }); NotesView := {viewFlags: 1, viewFormat: 1, viewBounds: {left: 10, top: 10, right: -10, bottom: -10}, viewJustify: 65776, viewSetupChildrenScript: // See the beforeScript for the definitions of the variable-size protos used in this print layout func() begin // If we haven't already create a list of kids, do it now and store it in a printformat slot // (not a slot in this child view) so we only have to do this once. if not printFormatKids then printFormatKids := :CreateVariableSizeKids(); if printFormatKids then begin // Create our stepChildren array. Note that we ignore the first 'reflowStart' number of kids // because we have already printed them on previous pages. This slot is created and initialized // in the print format's viewSetupFormScript. self.stepChildren := ArrayMunger([], 0, 0, printFormatKids, reflowStart, nil); if kDebugOn then print("After skipping" && reflowStart && "view templates/groups, there are"); if kDebugOn then print(length(printFormatKids) && "kids after reflow (for this page + future pages):"); if kDebugOn then print(printFormatKids); // note: see this view's viewSetupDoneScript to see how reflowStart is updated. end; else self.stepChildren := nil; end, viewSetupDoneScript: func() begin // After viewSetupChildrenScript and before viewSetupDoneScript, the system removes any children // that didn't fit on the page vertically if the view uses the vjReflow flag in viewJustify. // // The system removes the children from the actual view children list (for instance, the :ChildViewFrames() // list) and also removes it from self.stepChildren. We can find out how many items fit by checking the // length of stepChildren. That way, we know what view to start at when we go to the next page. if stepChildren then reflowStart := reflowStart + Length(stepChildren ); if kDebugOn then print("ReflowStart:"&& reflowStart); if kDebugOn then print("Length(stepChildren):"); end;, CreateVariableSizeKids: func() begin local kids; // Randomly generate some kids based on our variable-sized protos in the beforeScript kids := Array(50, nil); for i := 0 to 49 do begin local rand := Random(0,10); if rand = 0 then kids[i] := {_proto: kMySelfSizingPara, text: kBigText1}; else if rand = 1 then kids[i] := {_proto: kMySelfSizingPara, text: kBigText2}; else kids[i] := {_proto: kMySimpleVariProto, number: i + 1, sizeMultiplier: Random(1,3)}; end; kids; end, viewClass: 74 }; AddStepForm(indented frame, NotesView); pageNumber := {text: "", viewBounds: {top: -25, left: 0, right: 0, bottom: -5}, viewJustify: 8388790 , viewSetupFormScript: func() begin text := "Page" && NumberStr(myPageCounter) ; end, viewFont: simpleFont9+tsBold, _proto: @218 }; AddStepForm(_view000, pageNumber); constant |layout_PrintSimpleVari| := _view000; // End of file PrintSimpleVari // Beginning of file PrintEditviews // Before Script for "_view001" /* ** Newton Developer Technical Support Sample Code ** ** VariRoute, a Newton 2.0 routing example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-7 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. */ _view001 := { printNextPageScript: func() begin // If there are still views to print, then we do RedoChildren and return true, if printFormatKids and Length(printFormatKids) > reflowStart then begin // we check this in viewSetupFormScript to distinguish between // Initialization and RedoChildren; myPageCounter := myPageCounter + 1; :RedoChildren(); // rebuild all our views in preparation for the next page true; // return true to indicate "there are more pages" end; // ...else implicitly return nil to indicate "no more pages" end, symbol: kEditViewViewDefSym, viewSetupFormScript: func() begin myPageCounter := 1; // don't rely on fields.pageNumber to track pages! We track it // and increment it in printNextPageScript self.reflowStart := 0; // Used when using kReflowWrapperFunc inherited:?viewSetupFormScript(); // this method is defined internally end, formatInitScript: func(fields,theTarget) begin /* If you need to do prep something which takes a long time, and you are * worried about "timing out" a fax machine, do it here, not * in viewSetupFormScript!!! */ end, SetupItem: func(item, tInfo) begin /* If you have any "preprocessing" to do like set anything in the item or add * extra slots like version slots, or extra data, you can do it here, but if you are * trying to actually prep the visual shapes, you should do that in formatInitScript. */ inherited:?SetupItem(item, tInfo); // set the title; note that the string will be editable by the user... item.title := "VariRoute item: " & datentime(time()); item; end, title: "MyFormat", myPageCounter: nil, printFormatKids: nil // This is set in the notesView to be the array of Reflow-ed view templates , _proto: @200 }; NotesView := {viewFlags: 1, viewFormat: 593, viewBounds: {left: 10, top: 10, right: -10, bottom: -10}, viewJustify: 65776, viewSetupChildrenScript: func() begin // Note: Because this is sample code and I wanted to show a complex clEditView, I flattened a frame and included // in this package (see kFlattenedEditViewChildren in the file "Constants"). Here, we turn it into a an array of kids. // YOUR application would normally get this view templates from the 'viewChildren slot in a clEditView-based view. local kids := Translate(kFlattenedEditViewChildren, 'unflattener, nil, nil).data; // See the kReflowWrapperFunc file in this project for the kReflowWrapperFunc and more info about it. // It returns an array of view templates, including ones that may have appeared on previous pages. // We say "if not printFormatKids" because we only need to do this once and then save the array // in a slot in the printformat! if not printFormatKids then printFormatKids := call kReflowWrapperFunc with (kids, fancyFont12, :LocalBox()); if printFormatKids then begin // Create our stepChildren array. Note that we ignore the first 'reflowStart' number of kids // because we have already printed them on previous pages. This slot is created and initialized // in the print format's viewSetupFormScript. self.stepChildren := ArrayMunger([], 0, 0, printFormatKids, reflowStart, nil); if kDebugOn then print("After skipping" && reflowStart && "view templates/groups, there are"); if kDebugOn then print(length(printFormatKids) && "kids after reflow (for this page + future pages):"); if kDebugOn then print(printFormatKids); // note: see this view's viewSetupDoneScript to see how reflowStart is updated. end; else self.stepChildren := nil; end, viewSetupDoneScript: func() begin // After viewSetupChildrenScript and before viewSetupDoneScript, the system removes any children // that didn't fit on the page vertically if the view uses the vjReflow flag in viewJustify. // // The system removes the children from the actual view children list (for instance, the :ChildViewFrames() // list) and also removes it from self.stepChildren. We can find out how many items fit by checking the // length of stepChildren. That way, we know what view to start at when we go to the next page. if stepChildren then reflowStart := reflowStart + Length(stepChildren ); if kDebugOn then print("ReflowStart:"&& reflowStart); if kDebugOn then print("Length(stepChildren):"); end;, viewClass: 74 }; AddStepForm(_view001, NotesView); pageNumber := {text: "", viewBounds: {top: -25, left: 0, right: 0, bottom: -5}, viewJustify: 8388790 , viewSetupFormScript: func() begin text := "Page" && NumberStr(myPageCounter) ; end, viewFont: simpleFont9+tsBold, _proto: @218 }; AddStepForm(_view001, pageNumber); constant |layout_PrintEditviews| := _view001; // End of file PrintEditviews // Beginning of file PrintBigText // Before Script for "_view002" /* ** Newton Developer Technical Support Sample Code ** ** VariRoute, a Newton 2.0 routing example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-7 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. */ _view002 := { printNextPageScript: func() begin // If there are still views to print, then we do RedoChildren and return true, if printFormatKids and Length(printFormatKids) > reflowStart then begin // we check this in viewSetupFormScript to distinguish between // Initialization and RedoChildren; myPageCounter := myPageCounter + 1; :RedoChildren(); // rebuild all our views in preparation for the next page true; // return true to indicate "there are more pages" end; // ...else implicitly return nil to indicate "no more pages" end, symbol: kBigTextViewDefSym, viewSetupFormScript: func() begin myPageCounter := 1; // don't rely on fields.pageNumber to track pages! We track it // and increment it in printNextPageScript self.reflowStart := 0; // Used when using kReflowWrapperFunc inherited:?viewSetupFormScript(); // this method is defined internally end, formatInitScript: func(fields,theTarget) begin /* If you need to do prep something which takes a long time, and you are * worried about "timing out" a fax machine, do it here, not * in viewSetupFormScript!!! */ end, SetupItem: func(item, tInfo) begin /* If you have any "preprocessing" to do like set anything in the item or add * extra slots like version slots, or extra data, you can do it here, but if you are * trying to actually prep the visual shapes, you should do that in formatInitScript. */ inherited:?SetupItem(item, tInfo); // set the title; note that the string will be editable by the user... item.title := "VariRoute item: " & datentime(time()); item; end, title: "MyFormat", myPageCounter: nil, printFormatKids: nil // This is set in the notesView to be the array of Reflow-ed view templates , _proto: @200 }; NotesView := {viewFlags: 1, viewFormat: 593, viewBounds: {left: 10, top: 10, right: -10, bottom: -10}, viewJustify: 65776, viewSetupChildrenScript: func() begin // We say "if not printFormatKids" because we only need to do this once and then save the array // in a slot in the printformat! if not printFormatKids then begin local bigText := { viewClass: clParagraphView, viewBounds: RelBounds(0,0,0,0), viewFont: fancyFont18, viewJustify: vjTopV + vjLeftH, // When using the reflow function, do NOT use "full" justification viewFormat: vfNone, viewFlags: vVisible + vCalculateBounds, text: kVeryLongText, // see the file "Constants" }; // See the kReflowWrapperFunc file in this project for the function and more info about it. // It returns an array of view templates, including ones that may have appeared on previous pages. printFormatKids := call kReflowWrapperFunc with ([bigText], fancyFont18, :LocalBox()); if kDebugOn then print("Number of total kids when printing big text:" && Length(printFormatKids)); end; if printFormatKids then begin // Create our stepChildren array. Note that we ignore the first 'reflowStart' number of kids // because we have already printed them on previous pages. This slot is created and initialized // in the print format's viewSetupFormScript. self.stepChildren := ArrayMunger([], 0, 0, printFormatKids, reflowStart, nil); if kDebugOn then print("After skipping" && reflowStart && "view templates/groups, there are"); if kDebugOn then print(length(printFormatKids) && "kids after reflow (for this page + future pages):"); if kDebugOn then print(printFormatKids); // note: see this view's viewSetupDoneScript to see how reflowStart is updated. end; else self.stepChildren := nil; end, viewSetupDoneScript: func() begin // After viewSetupChildrenScript and before viewSetupDoneScript, the system removes any children // that didn't fit on the page vertically if the view uses the vjReflow flag in viewJustify. // // The system removes the children from the actual view children list (for instance, the :ChildViewFrames() // list) and also removes it from self.stepChildren. We can find out how many items fit by checking the // length of stepChildren. That way, we know what view to start at when we go to the next page. if stepChildren then reflowStart := reflowStart + Length(stepChildren ); if kDebugOn then print("ReflowStart:"&& reflowStart); if kDebugOn then print("Length(stepChildren):"); end;, viewClass: 74 }; AddStepForm(_view002, NotesView); pageNumber := {text: "", viewBounds: {top: -25, left: 0, right: 0, bottom: -5}, viewJustify: 8388790 , viewSetupFormScript: func() begin text := "Page" && NumberStr(myPageCounter) ; end, viewFont: simpleFont9+tsBold, _proto: @218 }; AddStepForm(_view002, pageNumber); constant |layout_PrintBigText| := _view002; // End of file PrintBigText // Beginning of file VariRoute.t // Before Script for "myBase" /* ** Newton Developer Technical Support Sample Code ** ** VariRoute, a Newton 2.0 routing example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-7 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. */ myBase := {viewBounds: {left: 0, top: 0, right: 236, bottom: 324}, appSymbol: kAppSymbol, viewSetupFormScript: func() viewBounds := GetAppParams().appAreaBounds;, myFormats: { viewFormat1: GetLayout("PrintSimpleVari"), viewFormat2: GetLayout("PrintEditviews"), viewFormat3: GetLayout("PrintBigText"), // put your other formats in this frame and then check out the code in // the install/removescripts that uses it... };, ReorientToScreen: ROM_defRotateFunc // Allow landscape mode , viewFlags: 1, viewFormat: 0, declareSelf: 'base, GetTargetInfo: // the targetType will always be 'routing for routing operations // This function is also called for filing and find func(targetType) begin local theTargetInfo := { target: WhichType_RadioGroup.ClusterValue, // this will contain a frame like {class: ..., whateverdata: ...} targetView: base, // the base view (because of the 'declareSelf slot set to 'base) appSymbol: kAppSymbol, // targetInfo.appSymbol is used by some transports // However, note that the Action button *also* looks in its own // view context to find the appSymbol slot. Usually it is found in // the base view because NTK creates it. However, for floaters // with Action buttons, you may need to add an appSymbol slot! // If the target is a soup entry and you support filing, also include a 'targetStore slot here... }; theTargetInfo; end, viewClass: 74 }; _view003 := {title: kAppName, _proto: @229}; AddStepForm(myBase, _view003); instructions := { text: kHelpString // see the "Constants" file , viewBounds: {left: 30, top: 17, right: -30, bottom: 35}, viewJustify: 50, _proto: @218 }; AddStepForm(myBase, instructions); WhichType_RadioGroup := {viewBounds: {left: 10, top: 50, right: -10, bottom: -30}, viewFlags: 1, viewFormat: 0, viewJustify: 240, _proto: @203 }; AddStepForm(myBase, WhichType_RadioGroup); StepDeclare(myBase, WhichType_RadioGroup, 'WhichType_RadioGroup); Simple Variable-Size Views := { buttonValue: {class: kMySimpleVariableSizeViewClass}; // we'll make up the data in the print format... , viewBounds: {left: 30, top: 30, right: 200, bottom: 72}, text: "Simple Variable-Size Views", viewValue: nil, viewFont: ROM_fontSystem12, viewSetupFormScript: // be sure to call inherited:?ViewSetupFormScript() func() begin viewValue := buttonValue; clusterValue := buttonValue; inherited:?ViewSetupFormScript(); end, _proto: @202 }; AddStepForm(WhichType_RadioGroup, Simple Variable-Size Views); StepDeclare(WhichType_RadioGroup, Simple Variable-Size Views, ' Simple Variable-Size Views); Complex clEditView Views := { buttonValue: {class: kMyEditViewDataClass}// we'll make up the data in the print format... , viewBounds: {left: 30, top: 80, right: 200, bottom: 120}, text: "Complex clEditView Views", viewFont: ROM_fontSystem12, _proto: @202 }; AddStepForm(WhichType_RadioGroup, Complex clEditView Views); Huge Text Views := { buttonValue: {class: kMyBigTextViewClass}; // we'll add the actual text in the print format , viewBounds: {left: 30, top: 130, right: 200, bottom: 176}, text: "Huge Text Views", viewFont: ROM_fontSystem12, _proto: @202 }; AddStepForm(WhichType_RadioGroup, Huge Text Views); _view004 := { menuRightButtons: [ protoActionButton, ], menuLeftButtons: [{ _proto: protoInfoButton, DoInfoAbout: func() :Notify(kNotifyQAlert, kAppName, kAboutString), DoInfoHelp: func() :Notify(kNotifyQAlert, kAppName, kHelpString) }, ], _proto: @401 }; AddStepForm(myBase, _view004); constant |layout_VariRoute.t| := myBase; // End of file VariRoute.t // Beginning of text file Install&RemoveScripts.f /* ** Newton Developer Technical Support Sample Code ** ** VariRoute, a Newton 2.0 routing example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-7 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. */ InstallScript := func(partFrame) begin local myApp := partFrame.theForm; RegisterViewDef(myApp.MyFormats.viewFormat1, kMySimpleVariableSizeViewClass); RegisterViewDef(myApp.MyFormats.viewFormat2, kMyEditViewDataClass); RegisterViewDef(myApp.MyFormats.viewFormat3, kMyBigTextViewClass); end; // run when application and/or card with app removed // cleanup routing stuff RemoveScript := func(partFrame) begin UnregisterViewDef(kSimpleVariViewDefSym, kMySimpleVariableSizeViewClass); UnregisterViewDef(kEditViewViewDefSym, kMyEditViewDataClass); UnregisterViewDef(kBigTextViewDefSym, kMyBigTextViewClass); end; // End of text file Install&RemoveScripts.f