3 lines
17 KiB
HTML
3 lines
17 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>13-WHAT-ARE-MENUS</title><link href="navigation.css" rel="stylesheet" type="text/css"/><link href="document.css" rel="stylesheet" type="text/css"/></head><body><p class="top_nav"><a href="part15.htm">< Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part17.htm">Next ></a></p><h1 style="padding-top: 3pt;padding-left: 35pt;text-indent: 0pt;text-align: left;"><a name="bookmark15">13. WHAT ARE MENUS?</a></h1><p style="padding-left: 35pt;text-indent: 0pt;line-height: 6pt;text-align: left;"><span><img width="640" height="8" alt="image" src="Image_086.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">While Medley provides a number of menus of its own (see Chapter 3), this section</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">addresses the menus you wish to create. You will learn how to create a menu, display a menu, and define functions that make your menu useful. Menus are instances of</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">records (see Chapter 24). There are 27 fields that determine the composition of every menu. Because Medley provides default values for most of these descriptive fields, you need to familiarize yourself with only a few that we describe in this section.</p><p style="padding-top: 7pt;padding-bottom: 2pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">Two of these fields, the <span class="s3">TITLE </span>of your menu, and the <span class="s3">ITEMS </span>you wish it to contain, can be typed into the executive window as shown below:</p><p style="padding-left: 191pt;text-indent: 0pt;text-align: left;"><span><img width="318" height="143" alt="image" src="Image_087.gif"/></span></p><p style="padding-top: 9pt;padding-left: 243pt;text-indent: 0pt;text-align: left;">Figure 13-1. Creating a menu</p><p style="padding-top: 5pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">Note that creating a menu does not display it. <span class="s3">MY.MENU </span>is set to an instance of a menu record that specifies how the menu will look, but the menu is not displayed.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Displaying Menus </h2><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">Typing either the <span class="s3">MENU </span>or <span class="s3">ADDNENU </span>functions will display your menu on the screen. <span class="s3">MENU </span>implements pop-up menus, like the Background Menu or the Window Menu. <span class="s3">ADDMENU </span>puts menus into a semi-permanent window on the screen, and lets you select items from it.</p><p class="s3" style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;line-height: 164%;text-align: left;">(MENU MENU POSITION) <span class="p">pops up a menu at a particular position on the screen. Type:</span></p><p class="s3" style="padding-left: 143pt;text-indent: 0pt;text-align: left;">(MENU MY.MENU NIL)</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">to position the menu at the end of the mouse cursor. Note that the <span class="s3">POSITION </span>argument is <span class="s3">NIL</span>. In order to go on, you must either choose an item, or move outside the menu</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">window and press a mouse button. When you do either, the menu will disappear. If you choose an item, then want to choose another, the menu must be redisplayed.</p><p class="s3" style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">(ADDMENU <span class="s4">menu window position</span>) <span class="p">positions a permanent menu on the screen, or in an existing window.</span></p><p style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Type:</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(ADDMENU MY.MENU)</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 106%;text-align: left;">to display the menu as shown in Figure 13-2. This menu will remain active, (will stay on the screen) without stopping all the other processes. Because <span class="s3">ADDMENU </span>can display a menu without stopping all other processes, it is very popular in users programs.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">If window is specified, the menu is displayed in that window. If window is not specified, a window the correct size for the menu is created, and the menu is displayed in that</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">window.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">If position is not specified, the menu appears at the current position of the mouse cursor.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 221pt;text-indent: 0pt;text-align: left;"><span><img width="238" height="62" alt="image" src="Image_088.gif"/></span></p><p style="padding-top: 5pt;padding-left: 111pt;text-indent: 0pt;text-align: center;">Figure 13-2. Simple MenuDisplayed with <span class="s3">ADDMENU</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Getting Menus to Do Stuff </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">One way to make a menu do things is to specify more about the menu items. Instead of items simply being the strings or atoms that will appear in the menu, items can be lists, each list with three elements (see Figure 13-3). The first element of each list is what</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">will appear in the menu; the second expression is what is evaluated, and the results of the evaluation returned, when the item is selected; and the third expression is the</p><p style="padding-bottom: 1pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">expression that should be printed in the Prompt window when a mouse button is held down while the mouse is pointing to that menu item. This third item should be thought of as help text for the user. If the third element of the list is NIL, the system responds with <b>Will select this item w hen you release the button</b>.</p><p style="padding-left: 148pt;text-indent: 0pt;text-align: left;"><span><img width="435" height="416" alt="image" src="Image_089.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 111pt;text-indent: 0pt;text-align: center;">Figure 13-3. Creating a Menu to do Things, then displaying it with the function</p><p class="s3" style="padding-left: 111pt;text-indent: 0pt;text-align: center;">ADDMENU</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">Now when an item is selected from <span class="s3">MY.MENU2</span>, something will happen. When a mouse button is held down, the expression typed as the third element in the item’s</p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 11pt;text-align: left;">specification will be printed in the Prompt window. (See Figure 13-4.)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;"><span><img width="552" height="111" alt="image" src="Image_090.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 111pt;text-indent: 0pt;text-align: center;">Figure 13-4. Mouse Button Held Down While Mouse Cursor SeIects <span class="s3">NEXT.QUESTION</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-bottom: 1pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">When the mouse button is released (i.e., the item is selected) the expression that was typed as the second element of the item’s specification will be run. (See Figure 13-5.)</p><p style="padding-left: 174pt;text-indent: 0pt;text-align: left;"><span><img width="364" height="156" alt="image" src="Image_091.gif"/></span></p><p style="padding-top: 5pt;padding-left: 111pt;text-indent: 0pt;text-align: center;">Figure 13-5. <span class="s3">NEXT-QUESTION </span>Selected</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-top: 8pt;padding-left: 35pt;text-indent: 0pt;text-align: left;">WHENHELDFN and WHENSELECTEDFN Fields of a Menu </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Another way to get a menu to do things is to define functions, and make them the</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">values of the menu’s <span class="s3">WHENHELDFN </span>and <span class="s3">WHENSELECTEDFN </span>fields. As the value of the</p><p class="s3" style="padding-left: 107pt;text-indent: 0pt;text-align: left;">WHENHELDFN <span class="p">field of a menu, the function you defined will be executed when you press</span></p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">and hold a mouse button inside the menu. As the value of the <span class="s3">WHENSELECTEDFN </span>field of a menu, the function you defined will be executed when you choose a menu item. This</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">example has the same functionality as the previous example, where each menu item was entered as a list of three items.</p><p style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">As an example, type in these two functions so that they can be executed when the menu is created and displayed:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-top: 6pt;padding-left: 143pt;text-indent: 0pt;line-height: 88%;text-align: left;">(DEFINEQ (MY.MENU3.WHENHELD (ITEM.SELECTED MENU.FROM BUTTON.PRESSED)</p><p class="s3" style="padding-left: 143pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(SELECTQ ITEM.SELECTED</p><p class="s3" style="padding-left: 179pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(QUIT (PROMPTPRINT "CHOOSE THIS TO STOP")</p><p class="s3" style="padding-left: 215pt;text-indent: -36pt;line-height: 88%;text-align: left;">(NEXT-QUESTION (PROMPTPRINT "CHOOSE THIS TO BE ASKED THE NEXT QUESTION"))</p><p class="s3" style="padding-left: 215pt;text-indent: -36pt;line-height: 88%;text-align: left;">(NEXT-TOPIC (PROMPTPRINT "CHOOSE THIS TO MOVE ON TO THE NEXT SUBJECT"))</p><p class="s3" style="padding-left: 215pt;text-indent: -36pt;line-height: 88%;text-align: left;">(SEE-TOPICS (PROMPTPRINT "CHOOSE THIS TO SEE THE TOPICS NOT YET LEARNED"))</p><p class="s3" style="padding-left: 179pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(ERROR (PROMPTPRINT "NO MATCH FOUND"))))</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 143pt;text-indent: 0pt;line-height: 88%;text-align: left;">(DEFINEQ (MY.MENU3.WHENSELECTED (ITEM.SELECTED MENU.FROM BUTTON.PRESSED)</p><p class="s3" style="padding-left: 143pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(SELECTQ ITEM.SELECTED</p><p class="s3" style="padding-left: 179pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(QUIT (PRINT "STOPPED")</p><p class="s3" style="padding-left: 179pt;text-indent: 0pt;line-height: 88%;text-align: left;">(NEXT-QUESTION (PRINT "HERE IS THE NEXT QUESTION")) (NEXT-TOPIC (PRINT "HERE IS THE NEXT SUBJECT")) (SEE-TOPICS (PRINT "THE FOLLOWING HAVE NOT BEEN</p><p class="s3" style="padding-left: 215pt;text-indent: 0pt;line-height: 10pt;text-align: left;">LEARNED . . ."))</p><p class="s3" style="padding-left: 179pt;text-indent: 0pt;line-height: 11pt;text-align: left;">(ERROR (PROMPTPRINT "NO MATCH FOUND"))))</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Now, to create the menu, type:</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(SETQ MY.MENU3 (CREATE MENU</p><p class="s3" style="padding-left: 167pt;text-indent: 0pt;line-height: 11pt;text-align: left;">TITLE <span class="s2"></span><span class="p"> </span>"PLEASE CHOOSE ONE OF THE ITEMS"</p><p class="s3" style="padding-left: 167pt;text-indent: 0pt;line-height: 86%;text-align: left;">ITEMS <span class="s2"></span><span class="p"> </span>’(QUIT NEXT-QUESTION NEXT-TOPIC SEE-TOPICS) WHENHELDFN <span class="s2"></span><span class="p"> </span>(FUNCTION MY.MENU3.WHENHELD) WHENSELECTEDFN <span class="s2"></span><span class="p"> </span>(FUNCTION MY.MENU3.WHENSELECTED)))</p><p style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">To see your menu work, type</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(ADDMENU MY.MENU3)</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">Now, due to executing the <span class="s3">WHENHELDFN </span>function, holding down any mouse button while pointing to a menu item will display an explanation of the item in the prompt window.</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">The screen will once again look like Figure 13-4 when the mouse button is held when the mouse cursor is pointing to the item <span class="s3">NEXT-TOPIC </span>.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 106%;text-align: justify;">Now due to executing the <span class="s3">WHENSELECTEDFN </span>function, releasing the mouse button to select an item will cause the proper actions for that item to be taken. The screen will once again look like Figure 13-5 when the item <span class="s3">NEXT-TOPIC </span>is selected. The crucial</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">thing to note is that the functions you defined for <span class="s3">WHENHELDFN </span>and <span class="s3">WHENSELECTEDFN</span></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">are automatically given the following arguments:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">1. The item that was sølected, <span class="s3">ITEM.SELECTED</span></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">2. The menu it was selected from, <span class="s3">MENU.FROM</span></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">3. The mousø button that was pressed <span class="s3">BUTTON PRESSED</span></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">These functions, <span class="s3">MY.MENU3.WHENHELD </span>and <span class="s3">MY.MENU3.WHENSELECTED</span>, were quoted</p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">using <span class="s3">FUNCTION </span>instead of <span class="s3">QUOTE </span>both for program readability and so that the compiler can produce faster code when the program is compiled. It is good style to quote</p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">functions in Lisp by using the function <span class="s3">FUNCTION </span>instead of <span class="s3">QUOTE</span>.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-top: 4pt;padding-left: 35pt;text-indent: 0pt;text-align: left;">Looking at a Menu’s Fields </h2><p class="s3" style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">INSPECT <span class="p">is a function that displays a list of the fields of a menu, and their values. Figure 13-6 shows the various fields of </span>MY.MENU3 <span class="p">when the function </span>(INSPECT</p><p class="s3" style="padding-bottom: 1pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">MY.MENU3) <span class="p">was called. Notice the values that were assigned by the examples, and all the defaults.</span></p><p style="padding-left: 125pt;text-indent: 0pt;text-align: left;"><span><img width="496" height="437" alt="image" src="Image_092.gif"/></span></p><p style="padding-top: 4pt;padding-left: 242pt;text-indent: 0pt;text-align: left;">Figure 13-6. <span class="s3">MY.MENU3 </span>Fields</p><p class="nav"> </p><p class="nav"> </p><p class="nav"><a href="part15.htm">< Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part17.htm">Next ></a></p><p class="nav"> </p></body></html>
|