3 lines
21 KiB
HTML
3 lines
21 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>12-WINDOWS</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="part14.htm">< Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part16.htm">Next ></a></p><h1 style="padding-top: 3pt;padding-left: 35pt;text-indent: 0pt;text-align: left;"><a name="bookmark14">12. WINDOWS AND REGIONS</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_082.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-top: 14pt;padding-left: 35pt;text-indent: 0pt;text-align: left;">Windows </h2><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Windows have two basic parts: an area on the screen containing a collection of pixels,</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">and a property list. The window properties determine how the window looks, the menus that can be accessed from it, what should happen when the mouse is inside the window and a mouse button is pressed, and soon.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 71pt;text-indent: 0pt;text-align: left;">CREATEW</h3><p style="padding-top: 8pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Some of the window’s properties can be specified when a window is created with the function <span class="s3">CREATE</span>W. In particular, it is easy to specify the size and position of the</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">window; its title; and the width of its borders.</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(CREATEW <span class="s4">region title borderw’idth</span>)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 106pt;text-indent: 0pt;line-height: 106%;text-align: left;">Region is a record (named <span class="s3">REGION </span>, with the fields <span class="s3">left</span>, <span class="s3">bottom </span>, <span class="s3">width</span>, and <span class="s3">height) </span>or a list. A region describes a rectangular area on the screen, the window’s dimensions and position. The fields left and bottom refer to the position of the bottom leff corner of</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">the region on the screen. Wi dth and height refer to the width and height of the region. The usable space inside the window will be smaller than the width and height, because some of the window’s region is consumed by the title bar, and some is taken by the</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">borders.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">Title is a string that will be placed in the title bar of the window.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">Borderwidth is the width of the border around the exterior of the window, in number of pixels.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">For example, typing:</p><p class="s3" style="padding-top: 7pt;padding-left: 173pt;text-indent: -30pt;text-align: left;">(SETQ MY.WINDOW (CREATEW (CREATEREGION l00 150 300 200) "THIS IS MY OWN WINDOW")</p><p style="padding-top: 9pt;padding-left: 106pt;text-indent: 0pt;text-align: left;">or</p><p class="s3" style="padding-top: 7pt;padding-left: 142pt;text-indent: 0pt;text-align: left;">(SETQ MY.WINDOW (CREATEW</p><p class="s3" style="padding-top: 1pt;padding-left: 173pt;text-indent: 6pt;line-height: 88%;text-align: left;">(CREATEW ’(100 150 300 200) "THIS IS MY OWN WINDOW")</p><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">produces a window with a default borderwidth. Note that you did not need to specify all the window’s properties (see Figure 12-1).</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 114pt;text-indent: 0pt;text-align: left;"><span><img width="460" height="337" alt="image" src="Image_083.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 237pt;text-indent: 0pt;text-align: left;">Figure 12-1. Creating a Window</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">In fact, if <span class="s3">(CREATEW) </span>is called without specifying a region, you will be prompted to sweep out a region for the window (see Chapter 10)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 71pt;text-indent: 0pt;text-align: left;">WlNDOWPROP</h3><p style="padding-top: 8pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">The function to access or add to any property of a window’s property list is</p><p class="s3" style="padding-left: 107pt;text-indent: 0pt;text-align: left;">WINDOWPROP<span class="p">.</span></p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(WINDOWPROP <span class="s4">window property </span><span class="p"><value></span>)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">When you use <span class="s3">WINDOWPROP </span>with only two arguments—window and property—it</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">returns the value of the window’s property. When you use <span class="s3">WINDOWPROP </span>with all three</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">arguments—window, property and value—it sets the value the window’s property to the value you inserted for the third argument.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">For example, consider the window, <span class="s3">MY WINDOW </span>, created using <span class="s3">(CREATEW)</span>. <span class="s3">TITLE </span>and</p><p class="s3" style="padding-left: 107pt;text-indent: 0pt;text-align: left;">REGION <span class="p">are both properties. Type</span></p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(WINDOWPROP MY.WINDOW ’TITLE)</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">and the value of <span class="s3">MY.WlNDOW</span>’s <span class="s3">TITLE </span>property is returned, <span class="s3">"THIS 1S MY OWN WINDOW"</span>. To change the title, use the <span class="s3">WINDOWPROP </span>function, and give it the window, the property title, and the new title of the window.</p><p class="s3" style="padding-top: 6pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(WINDOWPROP MY.WINDOW ’TITLE "MY FIRST WINDOW")</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">automatically changes the title and automatically updates the window. Now the window looks like Figure 12-2.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 116pt;text-indent: 0pt;text-align: left;"><span><img width="456" height="342" alt="image" src="Image_084.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 215pt;text-indent: 0pt;text-align: left;">Figure 12-2. <span class="s3">TITLE </span>is a Window Property</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">Altering the region of the window, <span class="s3">MY.WINDOW</span>, is also be done with <span class="s3">WINDOWPROP</span>, in the same way you changed the title. (Changing either of the first two numbers of a region</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">changes the position of the window on the screen. Changing either of the last two numbers changes the dimensions of the window itself.)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 71pt;text-indent: 0pt;text-align: left;">Getting Windows to Do Things</h3><p style="padding-top: 8pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">Four basic window properties will be discussed here: <span class="s3">CURSORINFN </span>, <span class="s3">CURSOROUTFN</span>, <span class="s3">CURSORMOVEDFN</span>, and <span class="s3">BUTTONEVENTFN</span>.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">A function can be stored as the value of the <span class="s3">CURSORlNFN </span>property of a window. It is called when the mouse cursor is moved into that window.</p><p style="padding-top: 6pt;padding-left: 48pt;text-indent: 0pt;text-align: center;">Look at the following example:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">1. First, create a window called <span class="s3">MY.WINDOW</span>. Type:</p><p class="s3" style="padding-top: 7pt;padding-left: 125pt;text-indent: 0pt;line-height: 11pt;text-align: left;">(SETQ MY.WINDQW</p><p class="s3" style="padding-left: 155pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(CREATEW</p><p class="s3" style="padding-left: 172pt;text-indent: 0pt;line-height: 88%;text-align: left;">(CREATEREGION 200 200 200 200) "THIS WINDOW WILL SCREAM!"))</p><p style="padding-top: 6pt;padding-left: 49pt;text-indent: 0pt;text-align: center;">This creates a window.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 125pt;text-indent: -17pt;line-height: 107%;text-align: left;">2. Now define the function <span class="s3">SCREAME </span>R. It will be stored on the property <span class="s3">CURSOR1NFN </span>. (Notice that this function has one argument, <span class="s3">WlNDOWNAM </span>E. All functions called from the property <span class="s3">CURSOR1NFN </span>are passed the window it was called from. So the value of <span class="s3">MY.WINDOW </span>is bound to <span class="s3">WINDOWNAME</span>. When it is called, <span class="s3">SCREAME</span>R simply rings</p><p style="padding-left: 125pt;text-indent: 0pt;text-align: left;">bells.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-top: 6pt;padding-left: 142pt;text-indent: -18pt;line-height: 88%;text-align: left;">(DEFINEQ (SCREAMER (WINDOWNAME) (RINGBELLS)</p><p class="s3" style="padding-left: 142pt;text-indent: 0pt;line-height: 88%;text-align: left;">(PROMPTPRINT "YAY - IT WORKS!") (RINGBELLS)))</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 125pt;text-indent: -17pt;line-height: 107%;text-align: left;">3. Now, alter that window’s <span class="s3">CURSORINFN </span>property, so that the system calls the function <span class="s3">SCREAMER </span>at the appropriate time. Type:</p><p class="s3" style="padding-top: 7pt;padding-left: 155pt;text-indent: -30pt;line-height: 88%;text-align: left;">(WINDOWPROP MY.WINDOW ’CURSORINFN (FUNCTION SCREAMER))</p><p style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">4. After this, when you move the mouse cursor into <span class="s3">MY.WlNDOW </span>, the <span class="s3">CURSORINFN</span></p><p style="padding-left: 125pt;text-indent: 0pt;text-align: left;">property’s function is called, and it rings bells twice.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">CURSORINFN <span class="p">is one of the many window properties that come with each window - just as </span>REGION <span class="p">and </span>TITLE <span class="p">did. Other properties include:</span></p><p class="s3" style="padding-top: 7pt;padding-left: 203pt;text-indent: -96pt;line-height: 107%;text-align: left;">CURSOROUTFN <span class="p">The function that is the value of this property is executed when the cursor is moved out of a window.</span></p><p class="s3" style="padding-top: 6pt;padding-left: 203pt;text-indent: -96pt;line-height: 107%;text-align: left;">CURSORMOVEDFN <span class="p">The function that is the value of this property is executed when the cursor is moved while it is inside the window.</span></p><p class="s3" style="padding-top: 6pt;padding-left: 203pt;text-indent: -96pt;line-height: 107%;text-align: left;">BUTTONEVENTFN <span class="p">The function that is the value of this property is executed when either the left or middle mouse buttons are pressed (or released).</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Figure 12-3 shows <span class="s3">MY.WlNDOW</span>’s properties. Notice that the <span class="s3">CURSORINFN </span>has the</p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">function <span class="s3">SCREAMER </span>stored in it. The properties were shown in this window using the function <span class="s3">INSPECT</span>. <span class="s3">INSPECT </span>is covered in Chapter 17.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 136pt;text-indent: 0pt;text-align: left;"><span><img width="400" height="382" alt="image" src="Image_085.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 140pt;text-indent: 0pt;text-align: left;">Figure 12-3. Inspecting <span class="s3">MY.WINDOW </span>for Mouse-Related Window Properties</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;">You can define functions for the values of the properties <span class="s3">CURSOROUTFN </span>and <span class="s3">CURSORMOVEDFN </span>in much the same way as you did for <span class="s3">CURSORINFN</span>. The function that is the value of the property <span class="s3">BUTTONEVENTF </span>N, however, can be specialized to respond in different ways, depending on which mouse button is pressed. This is explained in the</p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 11pt;text-align: left;">next section.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 71pt;text-indent: 0pt;text-align: left;">BUTTONEVENTFN</h3><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 107pt;text-indent: 0pt;line-height: 106%;text-align: left;">BUTTONEVENTFN <span class="p">is another property of a window. The function that is stored as the value of this property is called when tho mouse is inside the window, and a mouse button is pressed. As an example of how to use it, type:</span></p><p class="s3" style="padding-top: 7pt;padding-left: 173pt;text-indent: -30pt;line-height: 88%;text-align: left;">(WINDOWPROP MY.WINDOW ’BUTTONEVENTFN (FUNCTION SCREAMER))</p><p style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;line-height: 106%;text-align: left;">When the mouse cursor is moved into the window, bells will ring because of the <span class="s3">CURS0RlNFN</span>, but it will also ring bells when either the left or middle mouse button is pressed. Notice that the right mouse button functions as it usually does, with the</p><p style="padding-left: 106pt;text-indent: 0pt;line-height: 106%;text-align: left;">window manipulation menu. If only the left button should evoke the function <span class="s3">SCREAMER</span>, then the function can be written to do just this, using the function <span class="s3">MOUSESTATE</span>, and a form that only <span class="s3">MOUSESTATE </span>understands, <span class="s3">ONLY</span>. For example:</p><p class="s3" style="padding-top: 6pt;padding-left: 143pt;text-indent: 0pt;line-height: 11pt;text-align: left;">(DEFINEQ</p><p class="s3" style="padding-left: 173pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(SCREAMER2 (WINDOWNAME)</p><p class="s3" style="padding-left: 233pt;text-indent: -30pt;line-height: 88%;text-align: left;">(if (MOUSESTATE (ONLY LEFT)) then (RINGBELLS))))</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">In addition to <span class="s3">(ONLY LEFT)</span>, <span class="s3">MOUSESTATE </span>can also be passed <span class="s3">(ONLY MIDDLE) </span>, <span class="s3">(ONLY RIGHT) </span>or combinations of these (e.g. <span class="s3">(OR (ONLY LEFT) (ONLY MIDDLE))</span>). You do not need to use <span class="s3">ONLY </span>with <span class="s3">MOUSESTATE </span>for every application. <span class="s3">ONLY </span>means that that</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">button is pressed and no other.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">If you do write a function using <span class="s3">(ONLY RIGHT)</span>, be sure that your function also checks position of the mouse cursor. Even if you want your function to be executed when the mouse cursor is inside the window and the right button is pressed, there is a convention that the function <span class="s3">DOWINDOWCOM </span>should be executed when the mouse cursor is in the</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">title bar or the border of the window and the right mouse button is pressed. Please</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">program your windows using this tradition! For more information, please see Chapter 28 in the <i>IRM</i>.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 71pt;text-indent: 0pt;text-align: left;">Looking at a Window’s Properties</h3><p style="padding-top: 8pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">I<span class="s3">NSPECT </span>is a function that displays a list of the properties of a window, and their values. Figure 12.3 shows the <span class="s3">INSPECT </span>function run with <span class="s3">MY.WINDOW </span>. Note the</p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">properties introduced in <span class="s3">CREATEW </span>: <span class="s3">WBORDER </span>is the window’s border, <span class="s3">REG </span>is the region, and <span class="s3">WTITLE </span>is the window’s title.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Regions </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;">A region is a record, with the fields <span class="s3">LEFT</span>, <span class="s3">BOTTOM </span>, <span class="s3">WIDTH</span>, and <span class="s3">HEIGHT</span>. <span class="s3">LEFT </span>and <span class="s3">BOTTOM </span>refer to where the bottom left hand corner of the region is positioned on the screen. <span class="s3">WIDTH </span>and <span class="s3">HEIGHT </span>refer to the width and height of the region.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">CREATEREGION <span class="p">creates an instance of a record of type </span>REGION <span class="p">. Type:</span></p><p class="s3" style="padding-top: 7pt;padding-left: 57pt;text-indent: 0pt;text-align: center;">(SETQ MY.REGION (CREATEREGION 15 l00 200 450))</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 106%;text-align: left;">to create a record of type <span class="s3">REGION </span>that denotes a rectangle 200 pixels high, and 450 pixels wide, whose bottom left corner is at position (15, 100). This record instance can be passed to any function that requires a region as an argument, such as <span class="s3">CREATEW </span>, above.</p><p class="nav"> </p><p class="nav"> </p><p class="nav"><a href="part14.htm">< Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part16.htm">Next ></a></p><p class="nav"> </p></body></html>
|