home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / Newton Platform Info / Newton 2.0 Sample Code / Routing / CustomRoute-2 / CustomRoute.text < prev    next >
Encoding:
Text File  |  1995-11-21  |  13.1 KB  |  416 lines  |  [TEXT/MPS ]

  1. // Text of project CustomRoute written on 11/21/95 at 7:11 PM
  2. // Beginning of text file Constants
  3. /*
  4. **      Newton Developer Technical Support Sample Code
  5. **
  6. **      Custom Route, a Newton 2.0 routing example
  7. **
  8. **      by J. Christopher Bell, Newton Developer Technical Support
  9. **
  10. **      Copyright © 1994-5 by Apple Computer, Inc.  All rights reserved.
  11. **
  12. **      You may incorporate this sample code into your applications without
  13. **      restriction.  This sample code has been provided "AS IS" and the
  14. **      responsibility for its operation is 100% yours.  You are not
  15. **      permitted to modify and redistribute the source as "DTS Sample Code."
  16. **      If you are going to re-distribute the source, we require that you
  17. **      make it clear in the source that the code was descended from
  18. **      Apple-provided sample code, but that you've made changes.
  19. */
  20.  
  21. constant kMyMainDataDefSym     := '|myDataDef:customRoute:PIEDTS| ;
  22. constant kMyMainViewDefSym     := '|myViewDef:customRoute:PIEDTS| ;
  23. constant kMyFrameViewDefSym := '|myFrameViewDef:customRoute:PIEDTS| ;
  24.  
  25.  
  26. // Get the cup icon
  27. OpenResFile(home & "pictures");
  28. DefConst('kCupIcon, GetPictAsBits("minRouteIcon", nil));
  29. CloseResFile();
  30.  
  31.  
  32. /*
  33.  * This is a routing format which handles 'text and 'frame (despite the name, protoFrameFormat
  34.  * handles both types. If you want to handle just 'frames, override the dataTypes slot with ['frame].
  35.  *
  36.  * This will be registered in the application installScript with RegisterViewDef(...).
  37.  *
  38.  * Note that we won't necessarily be able to view the item in the iobox unless we write a 
  39.  * NON-ROUTING viewDef for kMyMainDataDefSym so that it can be viewed in the iobox item viewer.
  40.  */
  41. DefConst('kMyFrameRoutingFormat, {    
  42.     _proto:        protoFrameFormat,
  43.     title:        "CustomRoute - picture choice", 
  44.     version:    1, 
  45.     symbol:        kMyFrameViewDefSym, 
  46.     SetupItem:    func(item, targetInfo) 
  47.         begin
  48.             inherited:?SetupItem(item, targetInfo);
  49.             /*If you have any "preprocessing" to do like set anything in the item or add
  50.              * extra body slots like version slots, or extra data, you can do it here, but if you are
  51.              * trying to actually prep visual shapes, do that in formatInitScript.        
  52.              * 
  53.              * Note that by calling inherited, we get the equivalent of:
  54.              *        item.body := targetInfo.target;
  55.              * ...plus if the target is a soup entry alias, it resolves it...
  56.              *
  57.              * Only modify the item, not the target.
  58.              */
  59.  
  60.             // set the title; note that the string will be editable by the user...
  61.             item.title := "CustomRoute item: " & datentime(time());
  62.  
  63.             item;
  64.         end,
  65.     textScript: func(fields, target)
  66.         clone(target.data);    // our target.data should always be plain text
  67. });
  68. // End of text file Constants
  69. // Beginning of file PrintFormat
  70.  
  71. // Before Script for "_view000"
  72. /*
  73. **      Newton Developer Technical Support Sample Code
  74. **
  75. **      Custom Route, a Newton 2.0 routing example
  76. **
  77. **      by J. Christopher Bell, Newton Developer Technical Support
  78. **
  79. **      Copyright © 1994-5 by Apple Computer, Inc.  All rights reserved.
  80. **
  81. **      You may incorporate this sample code into your applications without
  82. **      restriction.  This sample code has been provided "AS IS" and the
  83. **      responsibility for its operation is 100% yours.  You are not
  84. **      permitted to modify and redistribute the source as "DTS Sample Code."
  85. **      If you are going to re-distribute the source, we require that you
  86. **      make it clear in the source that the code was descended from
  87. **      Apple-provided sample code, but that you've made changes.
  88. */
  89.  
  90. _view000 :=
  91.     {
  92.      printNextPageScript:
  93.        func()
  94.        begin
  95.           // for this example, always print 3 pages worth of stuff
  96.            if myPageCounter < 3 then
  97.                begin
  98.                    // we check this in viewSetupFormScript to distinguish between
  99.                    // Initialization and RedoChildren;
  100.                    myPageCounter := myPageCounter + 1;
  101.                    turningPages := true;    
  102.                    :RedoChildren();    // rebuild all our views in preparation for the next page
  103.                    turningPages := nil;
  104.                    true;
  105.                end;
  106.        end,
  107.      symbol: kMyMainViewDefSym,
  108.      viewSetupFormScript:
  109.        func()
  110.        begin
  111.            // we set this in printNextPageScript to distinguish between Initialization and RedoChildren();
  112.            if not turningPages then
  113.                myPageCounter := 1;                    // don't rely on fields.pageNumber to track pages! We track it
  114.                                                    // and increment it in printNextPageScript
  115.            inherited:?viewSetupFormScript();        // this method is defined internally
  116.        end,
  117.      formatInitScript:
  118.        func(fields,theTarget)
  119.        begin
  120.            /* If you need to do prep something which takes a long time, and you are 
  121.             * worried about "timing out" a fax machine, do it here, not
  122.             * in viewSetupFormScript!!!
  123.             */
  124.        end,
  125.      SetupItem:
  126.        func(item, tInfo)
  127.        begin
  128.            /* If you have any "preprocessing" to do like set anything in the item or add
  129.             * extra slots like version slots, or extra data, you can do it here, but if you are
  130.             * trying to actually prep the visual shapes, you should do that in formatInitScript.
  131.             */
  132.            inherited:?SetupItem(item, tInfo);
  133.            
  134.            
  135.            // set the title; note that the string will be editable by the user...
  136.            item.title := "CustomRoute item: " & datentime(time());
  137.            
  138.            item;
  139.        end,
  140.      title: "MyFormat",
  141.      myPageCounter: nil,
  142.      turningPages:
  143.        nil    // a flag to distinguish between initialization and RedoChildren in viewSetupFormScript
  144.        ,
  145.      _proto: @200
  146.     };
  147.  
  148. _view001 :=
  149.     {viewFlags: 1,
  150.      viewFormat: 593,
  151.      viewBounds: {left: 5, top: 5, right: 5, bottom: -5},
  152.      viewJustify: 240,
  153.      viewClass: 74
  154.     };
  155. AddStepForm(_view000, _view001);
  156.  
  157. _view002 :=
  158.     {viewFlags: 1,
  159.      icon: GetPictAsBits("Llama", nil),
  160.      viewFormat: nil,
  161.      viewBounds: {left: 0, top: 0, right: 0, bottom: 0},
  162.      viewJustify: 242,
  163.      viewClass: 76
  164.     };
  165. AddStepForm(_view001, _view002);
  166.  
  167.  
  168.  
  169.  
  170.  
  171. _view003 :=
  172.     {text: "<the user data>",
  173.      viewBounds: {top: -150, left: 0, right: 0, bottom: -20},
  174.      viewSetupFormScript:
  175.        func()
  176.            begin
  177.                text := "Custom data from input line: ";
  178.                if target.data and StrLen(target.data) > 0 then
  179.                    text := text & "\n‘" & target.data & "’" ;
  180.                else
  181.                    text := text & "\n<empty field>";
  182.            end,
  183.      viewFont: fancyFont18+tsBold,
  184.      viewJustify: 178,
  185.      _proto: @218
  186.     };
  187. AddStepForm(_view000, _view003);
  188.  
  189.  
  190.  
  191. pageNumber :=
  192.     {text: "Static Text",
  193.      viewBounds: {top: -25, left: 0, right: 0, bottom: -5},
  194.      viewJustify: 8388790
  195.      ,
  196.      viewSetupFormScript:
  197.        func()
  198.        begin
  199.           text := "Page" && NumberStr(myPageCounter) ;
  200.        end,
  201.      viewFont: simpleFont18+tsBold,
  202.      debug: "pageNumber",
  203.      _proto: @218
  204.     };
  205. AddStepForm(_view000, pageNumber);
  206.  
  207.  
  208.  
  209.  
  210. constant |layout_PrintFormat| := _view000;
  211. // End of file PrintFormat
  212. // Beginning of file CustomRoute.t
  213.  
  214. // Before Script for "myBase"
  215. /*
  216. **      Newton Developer Technical Support Sample Code
  217. **
  218. **      Custom Route, a Newton 2.0 routing example
  219. **
  220. **      by J. Christopher Bell, Newton Developer Technical Support
  221. **
  222. **      Copyright © 1994-5 by Apple Computer, Inc.  All rights reserved.
  223. **
  224. **      You may incorporate this sample code into your applications without
  225. **      restriction.  This sample code has been provided "AS IS" and the
  226. **      responsibility for its operation is 100% yours.  You are not
  227. **      permitted to modify and redistribute the source as "DTS Sample Code."
  228. **      If you are going to re-distribute the source, we require that you
  229. **      make it clear in the source that the code was descended from
  230. **      Apple-provided sample code, but that you've made changes.
  231. */
  232.  
  233. myBase :=
  234.     {viewBounds: {left: 0, top: 2, right: 236, bottom: 326},
  235.      appSymbol: kAppSymbol,
  236.      title: "CustomRoute",
  237.      viewSetupFormScript:
  238.        func()
  239.            viewBounds := GetAppParams().appAreaBounds;  // should define max/min, but we're lazy
  240.        ,
  241.      PutAwayScript:
  242.        func(item)
  243.        begin
  244.            /* your app might be asked to put away something you don't know about. Return
  245.             * nil if you don't know how to deal with it!
  246.             */
  247.            if classof(item.body) <> kMyMainDataDefSym or TargetIsCursor(item.body) then
  248.                return nil;
  249.                        
  250.            :Open();  // we might not be open!
  251.        
  252.            // This is the place where you could get wild and move the information
  253.            // into soups, other apps, and otherwise extract the information.
  254.            if item.body.data then
  255.                SetValue(theLine, 'text, item.body.data);
  256.            
  257.            true; // return true if it was put away successfully
  258.        end,
  259.      GetActiveView:
  260.        func()
  261.            begin
  262.                printFormatView; // return the current "active" view (for Intelligent Assistant)
  263.            end,
  264.      myFormats:
  265.        {
  266.            viewFormat:    GetLayout("PrintFormat"),
  267.            myFrameFormat:  kMyFrameRoutingFormat,    // see Constants file
  268.            // put your other formats in this frame and then check out the code in
  269.            // the install/removescripts that uses it...
  270.        };,
  271.      ReorientToScreen:
  272.        ROM_defRotateFunc  // Allow landscape mode
  273.        ,
  274.      debug: "myBase",
  275.      _proto: @157
  276.     };
  277.  
  278. printFormatView :=
  279.     {viewBounds: {left: 10, top: 37, right: -10, bottom: 156},
  280.      viewFlags: 1,
  281.      viewFormat: 336,
  282.      routeScripts:
  283.        [
  284.         {title: "Drink tea", routeScript: 'calmScript, icon: kCupIcon}, // defined in constants file
  285.         {title: "Duplicate", routeScript: 'duplicateScript, icon: ROM_routeDuplicateIcon},
  286.         {title: "Delete", routeScript: 'deleteScript, icon: ROM_routeDeleteIcon},
  287.        ],
  288.      GetTargetInfo:
  289.        func(targetType)
  290.        begin
  291.            // the targetType will always be 'routing for routing operations
  292.            // This function is also called for filing and find
  293.            
  294.            local theFrame := {
  295.                target: { 
  296.                    class: kMyMainDataDefSym,  // set unique class (and register viewDefs on this symbol!)
  297.                    data: theLine.text
  298.                },
  299.                targetView: theLine,
  300.                appSymbol: kAppSymbol,
  301.            };
  302.            // Note: if the target is a soup entry, then also include a targetStore slot for use by filing...
  303.            
  304.            theFrame;
  305.        end,
  306.      calmScript:
  307.        func(target, targetView)
  308.            begin
  309.               local oldText := theLine.text;
  310.               :SysBeep();
  311.               SetValue(theLine, 'text, "Mellow out! (drink peppermint tea?)");
  312.               RefreshViews();
  313.               theLine:Hilite(true);
  314.               sleep(120);
  315.               theLine:Hilite(nil);
  316.               SetValue(theLine, 'text, oldText);
  317.            end,
  318.      deleteScript:
  319.        func(target, targetView)
  320.        begin
  321.            if kDebugOn then print("Delete...");
  322.            
  323.            SetValue(theLine, 'text, clone(""));
  324.        end,
  325.      duplicateScript:
  326.        func(target, targetView)
  327.        begin
  328.            if kDebugOn then print("Duplicate...");
  329.            
  330.            // Umm...this is how our app will show duplication, but you would normally do 
  331.            // duplication by DeepCloning the target and creating a new soup entry...
  332.            SetValue(theLine, 'text, theLine:GetRichString() && "and" && theLine:GetRichString() );
  333.        end,
  334.      viewJustify: 48,
  335.      debug: "printFormatView",
  336.      viewClass: 74
  337.     };
  338. AddStepForm(myBase, printFormatView);
  339. StepDeclare(myBase, printFormatView, 'printFormatView);
  340.  
  341. theLine :=
  342.     {viewBounds: {left: 10, top: 0, right: -10, bottom: -20},
  343.      text: "Text",
  344.      viewJustify: 240,
  345.      debug: "theLine",
  346.      _proto: @185
  347.     };
  348. AddStepForm(printFormatView, theLine);
  349. StepDeclare(myBase, theLine, 'theLine);
  350.  
  351.  
  352.  
  353. _view004 :=
  354.     {
  355.      menuRightButtons:
  356.        [
  357.            protoActionButton,
  358.        ],
  359.      _proto: @401
  360.     };
  361. AddStepForm(printFormatView, _view004);
  362.  
  363. // After Script for "_view004"
  364. thisView := _view004;
  365. thisView._proto := newtStatusBarNoClose;    // not in platform file yet ••
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373. constant |layout_CustomRoute.t| := myBase;
  374. // End of file CustomRoute.t
  375. // Beginning of text file Install&RemoveScripts.f
  376. /*
  377. **      Newton Developer Technical Support Sample Code
  378. **
  379. **      Custom Route, a Newton 2.0 routing example
  380. **
  381. **      by J. Christopher Bell, Newton Developer Technical Support
  382. **
  383. **      Copyright © 1994-5 by Apple Computer, Inc.  All rights reserved.
  384. **
  385. **      You may incorporate this sample code into your applications without
  386. **      restriction.  This sample code has been provided "AS IS" and the
  387. **      responsibility for its operation is 100% yours.  You are not
  388. **      permitted to modify and redistribute the source as "DTS Sample Code."
  389. **      If you are going to re-distribute the source, we require that you
  390. **      make it clear in the source that the code was descended from
  391. **      Apple-provided sample code, but that you've made changes.
  392. */
  393.  
  394.  
  395. InstallScript := func(partFrame)
  396.     begin
  397.         local myApp := partFrame.theForm;
  398.         
  399.         RegisterViewDef(myApp.MyFormats.viewFormat, kMyMainDataDefSym);
  400.         RegisterViewDef(myApp.MyFormats.myFrameFormat, kMyMainDataDefSym);
  401.     end;
  402.  
  403.  
  404. // run when application and/or card with app removed
  405. // cleanup routing stuff
  406. RemoveScript := func(partFrame)
  407.     begin
  408.         UnregisterViewDef(kMyMainViewDefSym, kMyMainDataDefSym);
  409.         UnregisterViewDef(kMyFrameViewDefSym, kMyMainDataDefSym);
  410.     end;
  411.  
  412. // End of text file Install&RemoveScripts.f
  413.  
  414.  
  415.  
  416.