The "SysClass Examples.pgs" file contains the System Classes and a number of subclasses of the Window class. Each subclass is a window that illustrates the features of a particular system class (such as Check Box). Each class contains methods that illustrate how to do simple but useful things with the System Class in question (e.g., check a check box, or change the font in a text item).
Select Run from the Exec menu and open the various example windows in turn. To see the click method of any window item or menu item, shift-option-cmd-click on it while the application is running. This is a good way to start exploring this example.
CLASS: Window Examples
• open from library
Executed when you select "Window (from library)" from the Examples menu. Shows you how to find a window that already exists in the application's library and open it.
• open from class
Executed when you select "Window (from class)" from the Examples menu. Shows you how to create a new window instance and open it.
• close button
Executed when you click on the Close button in the Window Examples window. Closes the window.
• move left
Executed when you click on the Left button in the Window Examples window. Moves the window to the left by setting the location attribute.
• move right
Executed when you click on the Right button in the Window Examples window. Moves the window to the right by setting the location attribute.
• make bigger
Executed when you click on the Bigger button in the Window Examples window. Makes the window bigger by setting the size attribute.
• make smaller
Executed when you click on the Smaller button in the Window Examples window. Makes the window smaller by setting the size attribute.
CLASS: Menu Examples
There is a special menu that only appears when this window is active. The menu's title is "Special" and just contains some dummy menu items for demonstrating some of the manipulation of menus that you can do with Prograph.
• open window
Executed when you select "Menu Examples" from the Examples menu. Creates an instance of class "Menu Examples" and opens it by calling Window/Open which sets the active? attribute to TRUE.
• Close
Executed when you click on the close box for this window. Differs from Close in class Window only in that it removes the Special menu before closing the window.
• special menu
Executed when the Menu Examples window comes to the front or ceases to be the front window. Displays or removes the Special menu by setting its active? attribute.
• add item
Executed when you click on the Add Item button in the Menu Examples window. Uses the sc-insert-item primitive to add a new menu item called "New Item" to the end of the Special menu.
• set checked
Executed when you click on the "Checked?" check box in the Menu Examples window. Checks or unchecks the item named "Check Item" in the Special menu by setting the check? attribute.
• set name
Executed when you click on the ItemName radio set ("Eeenie", "Meenie", "Miney", "Mo") in the Menu Examples window. Changes the name of the second item in the Special menu by setting its name attribute.
• set enabled
Executed when you click on the "Enabled?" check box in the Menu Examples window. Enables or disables the entire Special menu by setting its enabled? attribute.
CLASS: Icon Examples
• open window
Executed when you select "Icon Examples" from the Examples menu. Creates an instance of class "Icon Examples" and opens it by calling Window/Open which sets the active? attribute to TRUE.
• change icon
Executed when you click on the radio set ("Telephone", "Trash", "People") in the Icon Examples window. Changes the icon in the window by setting its "rsrc number" attribute. The 3 icons were specifically added to the Prograph file with resource type 'ICON' and ids 128, 129 and 130 respectively.
CLASS: Check Box Examples
• open window
Executed when you select "Check Box Examples" from the Examples menu. Creates an instance of class "Check Box Examples" and opens it by calling Window/Open which sets the active? attribute to TRUE.
• set enabled
Executed when you click on the "Enabled?" check box in the Check Box Examples window. Enables or disables the check box in the top left corner of the window by setting its enabled? attribute.
• set name
Executed when you click on the radio set ("Example Check Box", "Coffee?", "Tea?", "Me?") in the Check Box Examples window. Changes the name of the check box in the top left corner of the window by setting its name attribute.
• set checked
Executed when you click on the Checked? check box in the Check Box Examples window. Checks or unchecks the check box in the top left corner of the window by setting its checked? attribute.
• also set checked
Executed when you click on the check box in the top left corner of the Check Box Examples window. Checks or unchecks the Checked? check box by setting its checked? attribute. (How many times can you say the word "check" in one sentence?!)
CLASS: Radio Set Examples
• open window
Executed when you select "Radio Set Examples" from the Examples menu. Creates an instance of class "Radio Set Examples" and opens it by calling Window/Open which sets the active? attribute to TRUE.
• change value
Executed when you click on the "Change Value" button in the Radio Set Examples window. Selects the next item in the example radio set by figuring out the index of the current selection, adding 1 to it or wrapping around to index 1 if it's the last item, figuring out the string corresponding to the new index, and setting the value attribute of the petBreeds radio set.
• show value
Executed when you click on the "Show Value" button in the Radio Set Examples window. Gets the value attribute of the petBreeds Radio Set and displays it in a sentence.
CLASS: Pop-up Examples
• open window
Executed when you select "Pop-up Examples" from the Examples menu. Creates an instance of class "Pop-up Examples" and opens it by calling Window/Open which sets the active? attribute to TRUE.
• set fixed
Executed when you click on the "Fixed?" check box in the Pop-up Examples window. Makes the example check box have fixed or non-fixed (variable) width by setting its fixed? attribute.
• set title
Executed when you click on the "Title?" check box in the Pop-up Examples window. Makes the example pop-up show or hide its title by setting its title? attribute.
• change values
Executed when you click on the radio set ("Colors", "Shapes") in the Pop-up Examples window. Changes the set of choices displayed in the example pop-up.
• display value
Executed whenever you make a new selection in the example pop-up. Displays the text of the new selection in the edit text above the pop-up.
• value as string
Useful method called from "display value". The value attribute of a pop-up is an index; this method returns the string associated with that index.
CLASS: Scroll List Examples
This window contains two lists, an edit text and a number of buttons. The list on the left can be edited with the Add, Delete and Change buttons. The Add button adds whatever is in the edit text to the list. The Delete button deletes the selected item from the list. The Change button replaces the selected item in the list with whatever is in the Edit Text. The »Copy» button between the two lists copies the selected item from the first list to the second.
• open window
Executed when you select "Scroll List Examples" from the Examples menu. Creates an instance of class "Scroll List Examples" and opens it by calling Window/Open which sets the active? attribute to TRUE.
• copy list value
Executed when you click on the "»Copy»" button in the Scroll List Examples window. Gets the selected item from the first list and adds it to the end of the second list; does nothing if nothing is selected in the first list.
• click list
Executed when you click on the first list. Uses the wait-double? primitive to see if it was a single or double click. For single clicks, it displays the selection in the edit text above the list. For double clicks, it calls the click method of the "»Copy»" button.
• add list entry
Executed when you click on the Add button in the Scroll List Examples window. Adds the text from the Edit Text to the end of the first scroll list. If there is no text in the Edit Text, does nothing.
• delete list entry
Executed when you click on the Delete button in the Scroll List Examples window. Deletes the currently selected item from the first scroll list. If there is nothing selected, does nothing.
• change list entry
Executed when you click on the Change button in the Scroll List Examples window. Replaces the currently selected item in the first scroll list with the contents of the Edit Text above it. If there is no text in the Edit Text, or if nothing is selected in the list, does nothing.
CLASS: Text Examples
This example just covers the rudiments of text on the Macintosh. For a much more sophisticated treatment, including multiple styles within a text item and Font, Style, Size and Edit menus that update to reflect the current selection, open and explore the Styled Text.pgs file.
• open window
Executed when you select "Text Examples" from the Examples menu. Creates an instance of class "Text Examples" and opens it by calling Window/Open which sets the active? attribute to TRUE.
• paste button
Executed when you click on the Paste button in the Text Examples window. Calls Menu/Paste, which simply calls the paste-text primitive with the currently selected edit text item from the front window. Inserts contents of the clipboard at the current text selection.
• clear button
Executed when you click on the Clear button in the Text Examples window. Calls Menu/Clear, which simply calls the clear-text primitive with the currently selected edit text item from the front window. Deletes current text selection.
• cut button
Executed when you click on the Cut button in the Text Examples window. Calls Menu/Cut, which simply calls the cut-text primitive with the currently selected edit text item from the front window. Deletes current text selection and places it on the clipboard.
• copy button
Executed when you click on the Copy button in the Text Examples window. Calls Menu/Copy, which simply calls the copy-text primitive with the currently selected edit text item from the front window. Puts current text selection on the clipboard, but doesn't delete it.
• set justification
Executed when you click on the radio set ( "Right" "Left" "Center" ) in the Text Examples window. Sets the justification attribute of the edit text to the correct Mac Constant corresponding to the radio button selected.
• select
Executed when you click on the "select "the"" button in the Text Examples window. Uses the "in" primitive to search for the next occurrence of "the" after the position of the current selection. Then sets the selection attribute of the edit text to select the string that was found.
• upper
Executed when you click on the Upper button in the Text Examples window. Converts the currently selected text to uppercase. Uses the extract-text and insert-text primitives, and the Mac toolbox call UprString.
• set size
Executed when you select an item from the Size pop-up in the Text Examples window. Sets the font size attribute of the edit text based on the pop-up selection.
• change font
Executed when you select an item from the Font pop-up in the Text Examples window. Sets the font attribute of the edit text based on the pop-up selection. Uses the Mac Toolbox call GetFNum.
• change style
Useful utility routine that uses bit operations to add or subtract an individual style component (e.g., bold or italic) into an existing combined style (e.g., bold-italic-underline ). Sets the font style attribute of the given edit text item.
• set bold
Executed when you click on the Bold check box in the Text Examples window. Calls the change style method to add or subtract bold from the current style of the edit text item.
• set italic
Executed when you click on the Italic check box in the Text Examples window. Calls the change style method to add or subtract italic from the current style of the edit text item.
• set underline
Executed when you click on the Underline check box in the Text Examples window. Calls the change style method to add or subtract underlining from the current style of the edit text item.
CLASS: Canvas Examples
• open window
Executed when you select "Canvas Examples" from the Examples menu. Creates an instance of class "Canvas Examples" and opens it by calling Window/Open which sets the active? attribute to TRUE.
• draw canvas
Executed whenever the canvas needs to be redrawn - i.e., when the window first displays, or when it covered by another window and uncovered again. Erases the area representing the maximum size of the drawing area of a Canvas, and then draws the contents. The actual drawing code is semi-complicated, using QuickDraw Mac toolbox calls like FrameOval, LineTo and FrameArc to draw the elements of the face after scaling everything to the current size of the limits (drawing area) of the canvas. It is not necessary to understand all of the drawing code to understand this example.
• change mood
Executed when you click on the "Mood" radio set ("happy", "sad", "smashed"). Forces the canvas to redraw to reflect the new mood.
• set limits
Executed when you click on the "Limits" radio set ( "default" "half" "double" "half horizontal" "half vertical" "double horizontal" "double vertical" ). Sets the limits attribute of the canvas to a new value calculated according to the selection in the radio set. The limits of a canvas are essentially the drawing area, and the scroll bars update to reflect this. The draw canvas method scales everything to fit within the current limits.
• scroll to end
Executed when you click on the "Scroll To End" button in the Canvas Examples window. Sets the origin attribute of the canvas in order to make it scroll.
How to Use in Your Program
-------------------------
Selectively load any method that seems useful. Most of the methods in this file are useful for learning and for stealing code from, but don't do much on their own.