home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / Newton Sample Code 1.1 / Proto Templates / Buttons-3 / Buttons.text < prev    next >
Encoding:
Text File  |  1994-02-28  |  9.9 KB  |  388 lines  |  [TEXT/MPS ]

  1.  
  2. // ---- End Project Data ----
  3.  
  4.  
  5. // ---- File Buttons.t ----
  6.  
  7. // Before Script for "baseView"
  8. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  9.  
  10. baseView :=
  11.    {title: "Buttons",
  12.     viewBounds: {top: 0, left: 0, right: 240, bottom: 336},
  13.     viewSetupFormScript:
  14.       func()
  15.       begin
  16.           // resize to fit on all "small" newtons.
  17.           local b := GetAppParams();
  18.           constant kMaxWidth := 240;
  19.           constant kMaxHeight := 336;
  20.           self.viewBounds := RelBounds(b.appAreaLeft, b.appAreaTop,
  21.                                                 MIN(b.appAreaWidth, kMaxWidth),
  22.                                                 MIN(b.appAreaHeight, kMaxHeight));
  23.       end,
  24.     _proto: protoApp,
  25.     debug: "baseView"
  26.    };
  27.  
  28.  
  29. // Before Script for "label1"
  30. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  31.  
  32. label1 := /* child of baseView */
  33.    {text: "Example of a popup text button:",
  34.     viewBounds: {left: 9, top: 17, right: 193, bottom: 41},
  35.     viewJustify: 0,
  36.     viewFont: simpleFont9,
  37.     _proto: protoStaticText,
  38.     debug: "label1"
  39.    };
  40. // View label1 is declared to baseView
  41.  
  42.  
  43.  
  44.  
  45. // Before Script for "PopupButton"
  46. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  47.  
  48. PopupButton := /* child of baseView */
  49.    {text: "PopUp",
  50.     viewBounds: {left: 75, top: 35, right: 147, bottom: 51},
  51.     buttonClickScript:
  52.       func()
  53.       begin
  54.       // note 0,0 for a topLeft is probably not as pretty as
  55.       // some things could be
  56.           DoPopup(popupList, 0, 0, self);
  57.       end,
  58.     popupList: ["No", "No Way", "Never", "Over My Dead Body"],
  59.     pickActionScript:
  60.       func(index)
  61.       // note you need to implement pickActionScript if you have a popupList
  62.       begin
  63.           Print("Selected index no " & index);
  64.       end,
  65.     pickCancelledScript:
  66.       func()
  67.       begin
  68.           Print("Popup cancelled");
  69.       end,
  70.     _proto: protoTextButton,
  71.     debug: "PopupButton"
  72.    };
  73. // View PopupButton is declared to baseView
  74.  
  75.  
  76.  
  77.  
  78. // Before Script for "label2"
  79. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  80.  
  81. label2 := /* child of baseView */
  82.    {text: "Example of a movable palette of buttons:",
  83.     viewBounds: {left: 9, top: 74, right: 193, bottom: 106},
  84.     viewJustify: 0,
  85.     viewFont: simpleFont9,
  86.     _proto: protoStaticText,
  87.     debug: "label2"
  88.    };
  89.  
  90.  
  91.  
  92.  
  93. // Before Script for "label3"
  94. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  95.  
  96. label3 := /* child of baseView */
  97.    {text: "Example of buttons that show states using drawing:",
  98.     viewBounds: {left: 9, top: 168, right: 196, bottom: 196},
  99.     viewJustify: 0,
  100.     viewFont: simpleFont9,
  101.     _proto: protoStaticText,
  102.     debug: "label3"
  103.    };
  104.  
  105.  
  106.  
  107.  
  108. // Before Script for "statusButton"
  109. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  110.  
  111. statusButton := /* child of baseView */
  112.    {viewFlags: 513,
  113.     viewFormat: 83887089,
  114.     viewBounds: {left: 28, top: 103, right: 202, bottom: 145},
  115.     viewClickScript:
  116.       func(unit)
  117.       begin
  118.           :Drag(unit, nil);    // move the button palette
  119.           true;
  120.       end,
  121.     viewclass: 74,
  122.     debug: "statusButton"
  123.    };
  124.  
  125.  
  126. // Before Script for "butt1"
  127. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  128.  
  129. butt1 := /* child of statusButton */
  130.    {text: "First",
  131.     viewBounds: {left: 18, top: 18, right: 58, bottom: 34},
  132.     buttonClickScript:
  133.       func()
  134.       begin
  135.           Print("Button 1 clicked -- buttonPalette");
  136.       end,
  137.     _proto: protoTextButton,
  138.     debug: "butt1"
  139.    };
  140. // View butt1 is declared to statusButton
  141.  
  142.  
  143.  
  144.  
  145. // Before Script for "butt2"
  146. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  147.  
  148. butt2 := /* child of statusButton */
  149.    {text: "Second",
  150.     viewBounds: {left: 66, top: 18, right: 106, bottom: 34},
  151.     buttonClickScript:
  152.       func()
  153.       begin
  154.           Print("Button 2 clicked -- buttonPalette");
  155.       end,
  156.     _proto: protoTextButton,
  157.     debug: "butt2"
  158.    };
  159. // View butt2 is declared to statusButton
  160.  
  161.  
  162.  
  163.  
  164. // Before Script for "butt3"
  165. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  166.  
  167. butt3 := /* child of statusButton */
  168.    {text: "Third",
  169.     viewBounds: {left: 114, top: 18, right: 162, bottom: 34},
  170.     buttonClickScript:
  171.       func()
  172.       begin
  173.           Print("Button 3 clicked -- buttonPalette");
  174.       end,
  175.     _proto: protoTextButton,
  176.     debug: "butt3"
  177.    };
  178. // View butt3 is declared to statusButton
  179.  
  180.  
  181.  
  182.  
  183. // Before Script for "_view000"
  184. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  185.  
  186. _view000 := /* child of statusButton */
  187.    {text: "Move me around!",
  188.     viewBounds: {left: 7, top: 2, right: 97, bottom: 11},
  189.     _proto: protoStaticText
  190.    };
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197. // Before Script for "StateButton"
  198. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  199.  
  200. StateButton := /* child of baseView */
  201.    {text: "Status",
  202.     viewBounds: {left: 75, top: 200, right: 142, bottom: 223},
  203.     viewJustify: 5,
  204.     theState: 'closed,
  205.     viewSetupFormScript:
  206.       func()
  207.       begin
  208.       // create the triangle object
  209.           closedTShape := MakePolygon('[5,5,10,10,5,15,5,5]);
  210.           openTShape := MakePolygon('[0,10,10,10,5,15,0,10]);
  211.       end,
  212.     OpenTShape: nil,
  213.     ClosedTShape: nil,
  214.     viewDrawScript:
  215.       // draw a notification inside the button
  216.       
  217.       func()
  218.       begin
  219.           if (theState = 'closed) then
  220.               :DrawShape(ClosedTShape, nil);
  221.       
  222.           if (theState = 'open) then
  223.               :DrawShape(OpenTShape, nil);
  224.       end,
  225.     buttonClickScript:
  226.       func()
  227.       begin
  228.       // switch between two states
  229.           if theState = 'closed then
  230.               theState := 'open;
  231.           else
  232.               theState := 'closed;
  233.       
  234.           :Dirty();            // force a dirty after this
  235.       end,
  236.     viewFormat: 67306065,
  237.     _proto: protoTextButton,
  238.     debug: "StateButton"
  239.    };
  240.  
  241.  
  242.  
  243.  
  244. // Before Script for "label4"
  245. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  246.  
  247. label4 := /* child of baseView */
  248.    {
  249.     text:
  250.       "Example of Button that looks like the protoShowBar (used for filing):",
  251.     viewBounds: {left: 9, top: 249, right: 193, bottom: 281},
  252.     viewJustify: 0,
  253.     viewFont: simpleFont9,
  254.     _proto: protoStaticText,
  255.     debug: "label4"
  256.    };
  257.  
  258.  
  259.  
  260.  
  261. // Before Script for "showBarButton"
  262. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  263.  
  264. showBarButton := /* child of baseView */
  265.    {text: "Button",
  266.     buttonClickScript:
  267.       // When clicked, call DoPopUp and send over the array of labels.
  268.       func()
  269.       begin
  270.       // Note that we are creating the frame array in RAM, why? Well,
  271.       // if the frame was pre-defined in the slot, it would be a ROM-readonly
  272.       // entity, and we would be unable to change the items on the flight --
  273.       // unless you cloned the whole frame and started to add more array entries
  274.       // to this cloned RAM object. Anyway, you are able to do both, I just showed
  275.       // the dynamic way of doing this, and I'm sure there are more designed ways
  276.       // to add entries to the popup frame.
  277.       
  278.           pop := SetLength([], 6);         // preallocate an array
  279.       
  280.       // Create the frame.
  281.       // Only one should have the mark, decide this here as well
  282.       
  283.          pop[0] := { item: "Unfiled", mark: $ }; 
  284.          IF currentSelection = 0 THEN
  285.             pop[0].mark := $\u221A;
  286.       
  287.          pop[1] := { item: "Business", mark: $ };
  288.          IF currentSelection = 1 THEN
  289.             pop[1].mark := $\u221A;
  290.       
  291.          pop[2] := { item: "Private", mark:  $ };
  292.          IF currentSelection = 2 THEN
  293.             pop[2].mark := $\u221A;
  294.       
  295.          pop[3] := { item: "Important", mark: $ };
  296.          IF currentSelection = 3 THEN
  297.             pop[3].mark := $\u221A;
  298.       
  299.          pop[4] := 'pickSeparator;
  300.       
  301.          pop[5] := { item: "Everything", mark: $ };
  302.          IF currentSelection = 5 THEN
  303.             pop[5].mark := $\u221A;
  304.        
  305.          DoPopUp(pop, 0, 2, self);
  306.       
  307.       // Another thing to remember with dynamic popups is that if you don't
  308.       // know the length and width of the strings, you have to precalculate
  309.       // this information using StrFontWidth and maybe truncate using StrTruncate.
  310.       
  311.       end,
  312.     viewBounds: {left: 74, top: 290, right: 145, bottom: 301},
  313.     pickActionScript:
  314.       // Update the label text in the button with the newly defined
  315.       // value.
  316.       func(index)
  317.       begin
  318.       // Get access to the newly selected value, and store it 
  319.          currentSelection := index;
  320.       
  321.       // Create new text and set it
  322.          SetValue(self, 'text,  $\uFC01 && pop[currentSelection].item);
  323.       end,
  324.     currentSelection: nil,
  325.     viewSetupFormScript:
  326.       func()
  327.       begin
  328.          currentSelection := 0;      // default label
  329.       
  330.       // In real life we would maybe get a default label and stuff it
  331.       // in here based on the currentSelection, or then do as I did below,
  332.       // create an undefined label, forcing the end user to select a
  333.       // label. Maybe a default label is a more user friendly thing to
  334.       // do...
  335.       
  336.          text := $\uFC01 && "Undefined";
  337.       end,
  338.     viewFormat: 337,
  339.     pop: nil,
  340.     _proto: protoTextButton,
  341.     debug: "showBarButton"
  342.    };
  343.  
  344.  
  345.  
  346.  
  347. // Before Script for "line1"
  348. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  349.  
  350. line1 := /* child of baseView */
  351.    {viewBounds: {left: 1, top: 68, right: 244, bottom: 70},
  352.     _proto: protoBorder,
  353.     debug: "line1"
  354.    };
  355.  
  356.  
  357.  
  358.  
  359. // Before Script for "line2"
  360. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  361.  
  362. line2 := /* child of baseView */
  363.    {viewBounds: {left: 1, top: 161, right: 244, bottom: 163},
  364.     _proto: protoBorder,
  365.     debug: "line2"
  366.    };
  367.  
  368.  
  369.  
  370.  
  371. // Before Script for "line3"
  372. // Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  373.  
  374. line3 := /* child of baseView */
  375.    {viewBounds: {left: -6, top: 241, right: 237, bottom: 243},
  376.     _proto: protoBorder,
  377.     debug: "line3"
  378.    };
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386. // ---- Beginning of section for non used Layout files ----
  387.  
  388. // End of output