Debian Codegraph @

info/gcl-tk/Lisp-Functions-Invoked-from-Graphics.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>Lisp Functions Invoked from Graphics (GCL TK Manual)</title>
7
8 <meta name="description" content="Lisp Functions Invoked from Graphics (GCL TK Manual)">
9 <meta name="keywords" content="Lisp Functions Invoked from Graphics (GCL TK Manual)">
10 <meta name="resource-type" content="document">
11 <meta name="distribution" content="global">
12 <meta name="Generator" content="makeinfo">
13 <link href="index.html" rel="start" title="Top">
14 <link href="wm.html#SEC_Contents" rel="contents" title="Table of Contents">
15 <link href="General.html" rel="up" title="General">
16 <link href="Linked-Variables.html" rel="next" title="Linked Variables">
17 <link href="Argument-Lists.html" rel="prev" title="Argument Lists">
18 <style type="text/css">
19 <!--
20 a.summary-letter {text-decoration: none}
21 blockquote.indentedblock {margin-right: 0em}
22 div.display {margin-left: 3.2em}
23 div.example {margin-left: 3.2em}
24 div.lisp {margin-left: 3.2em}
25 kbd {font-style: oblique}
26 pre.display {font-family: inherit}
27 pre.format {font-family: inherit}
28 pre.menu-comment {font-family: serif}
29 pre.menu-preformatted {font-family: serif}
30 span.nolinebreak {white-space: nowrap}
31 span.roman {font-family: initial; font-weight: normal}
32 span.sansserif {font-family: sans-serif; font-weight: normal}
33 ul.no-bullet {list-style: none}
34 -->
35 </style>
36
37
38 </head>
39
40 <body lang="en">
41 <span id="Lisp-Functions-Invoked-from-Graphics"></span><div class="header">
42 <p>
43 Next: <a href="Linked-Variables.html" accesskey="n" rel="next">Linked Variables</a>, Previous: <a href="Argument-Lists.html" accesskey="p" rel="prev">Argument Lists</a>, Up: <a href="General.html" accesskey="u" rel="up">General</a> &nbsp; [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
44 </div>
45 <hr>
46 <span id="Lisp-Functions-Invoked-from-Graphics-1"></span><h3 class="section">1.6 Lisp Functions Invoked from Graphics</h3>
47
48
49 <p>It is possible to make certain areas of a window mouse sensitive,
50 or to run commands on reception of certain events such as keystrokes,
51 while the focus is in a certain window. This is done by having
52 a lisp function invoked or some lisp form evaluated. We shall
53 refer to such a lisp function or form as a <em>command</em>.
54 </p>
55 <p>For example
56 </p>
57 <div class="example">
58 <pre class="example">(button '.button :text &quot;Hello&quot; :command '(print &quot;hi&quot;))
59 (button '.jim :text &quot;Call Jim&quot; :command 'call-jim)
60 </pre></div>
61
62 <p>In the first case when the window <code>.button</code> is clicked on, the
63 word &quot;hi&quot; will be printed in the lisp to standard output. In the
64 second case <code>call-jim</code> will be funcalled with no arguments.
65 </p>
66 <p>A command must be one of the following three types. What happens
67 depends on which type it is:
68 </p>
69 <dl compact="compact">
70 <dt>&lsquo;<samp>function</samp>&rsquo;</dt>
71 <dd><p>If the value satisfies <code>functionp</code> then it will be called with
72 a number of arguments which is dependent on the way it was bound,
73 to graphics.
74 </p></dd>
75 <dt>&lsquo;<samp>string</samp>&rsquo;</dt>
76 <dd><p>If the command is a string, then it is passed directly to <b>TCL/TK</b>
77 for evaluation on that side. Lisp will not be required for the
78 evaluation when the command is invoked.
79 </p></dd>
80 <dt>&lsquo;<samp>lisp form</samp>&rsquo;</dt>
81 <dd><p>Any other lisp object is regarded as a lisp form to be eval&rsquo;d, and
82 this will be done when the command is invoked.
83 </p></dd>
84 </dl>
85
86 <p>The following keywords accept as their value a command:
87 </p>
88 <div class="example">
89 <pre class="example"> :command
90 :yscroll :yscrollcommand
91 :xscroll :xscrollcommand
92 :scrollcommand
93 :bind
94 </pre></div>
95
96 <p>and in addition <code>bind</code> takes a command as its third argument,
97 see See <a href="bind.html">bind</a>.
98 </p>
99 <p>Below we give three different examples using the 3 possibilities for
100 a command: functionp, string, and lisp form. They all accomplish
101 exactly the same thing.
102 For given a frame <code>.frame</code> we could construct a listbox
103 in it as:
104 </p>
105 <div class="example">
106 <pre class="example">(listbox '.frame.listbox :yscroll 'joe)
107 </pre></div>
108
109 <p>Then whenever the listbox view position changes, or text is inserted,
110 so that something changes, the function <code>joe</code> will be invoked with 4
111 arguments giving the totalsize of the text, maximum number of units
112 the window can display, the index of the top unit, and finally the
113 index of the bottom unit. What these arguments are is specific
114 to the widget <code>listbox</code> and is documented See <a href="listbox.html">listbox</a>.
115 </p>
116 <p><code>joe</code> might be used to do anything, but a common usage is to have
117 <code>joe</code> alter the position of some other window, such as a scroll
118 bar window. Indeed if <code>.scrollbar</code> is a scrollbar then
119 the function
120 </p>
121 <div class="example">
122 <pre class="example">(defun joe (a b c d)
123 (.scrollbar :set a b c d))
124 </pre></div>
125
126 <p>would look after sizing the scrollbar appropriately for the percentage
127 of the window visible, and positioning it.
128 </p>
129 <p>A second method of accomplishing this identical, using a string (the
130 second type of command),
131 </p>
132
133 <div class="example">
134 <pre class="example">(listbox '.frame.listbox :yscroll &quot;.scrollbar set&quot;)
135 </pre></div>
136
137 <p>and this will not involve a call back to lisp. It uses the fact that
138 the <b>TK</b> graphics side understands the window name <code>.scrollbar</code> and
139 that it takes the <i>option</i> <code>set</code>. Note that it does not get
140 the <code>:</code> before the keyword in this case.
141 </p>
142 <p>In the case of a command which is a <i>lisp form</i> but is not installed
143 via <code>bind</code> or <code>:bind</code>, then the form will be installed as
144 </p>
145 <div class="example">
146 <pre class="example">#'(lambda (&amp;rest *arglist*) <i>lisp-form</i>)
147 </pre></div>
148
149 <p>where the <i>lisp-form</i> might wish to access the elements of the special
150 variable <code>*arglist*</code>. Most often this list will be empty, but for
151 example if the command was setup for <code>.scale</code> which is a <i>scale</i>,
152 then the command will be supplied one argument which is the new numeric
153 value which is the scale position. A third way of accomplishing the
154 scrollbar setting using a lisp form is:
155 </p>
156 <div class="example">
157 <pre class="example">(listbox '.frame.listbox :yscroll '(apply '.scrollbar :set *arglist*))
158 </pre></div>
159
160 <p>The <code>bind</code> command and <code>:bind</code> keyword, have an additional
161 wrinkle, see See <a href="bind.html">bind</a>. These are associated to an event in a
162 particular window, and the lisp function or form to be evaled must have
163 access to that information. For example the x y position, the window
164 name, the key pressed, etc. This is done via <i>percent symbols</i> which
165 are specified, see See <a href="bind.html">bind</a>.
166 </p>
167 <div class="example">
168 <pre class="example">(bind &quot;Entry&quot; &quot;&lt;Control-KeyPress&gt;&quot; '(emacs-move %W %A ))
169 </pre></div>
170
171 <p>will cause the function emacs-move to be be invoked whenever a control
172 key is pressed (unless there are more key specific or window specific
173 bindings of said key). It will be invoked with two arguments, the
174 first %W indicating the window in which it was invoked, and the second
175 being a string which is the ascii keysym which was pressed at the same
176 time as the control key.
177 </p>
178 <p>These <i>percent constructs</i> are only permitted in commands which are
179 invoked via <code>bind</code> or <code>:bind</code>. The lisp form which is passed
180 as the command, is searched for the percent constructs, and then a
181 function
182 </p>
183 <div class="example">
184 <pre class="example">#'(lambda (%W %A) (emacs-move %W %A))
185 </pre></div>
186
187 <p>will be invoked with two arguments, which will be supplied by the
188 <b>TK</b> graphics server, at the time the command is invoked. The
189 <code>*arglist*</code> construct is not available for these commands.
190 </p>
191 <hr>
192 <div class="header">
193 <p>
194 Next: <a href="Linked-Variables.html" accesskey="n" rel="next">Linked Variables</a>, Previous: <a href="Argument-Lists.html" accesskey="p" rel="prev">Argument Lists</a>, Up: <a href="General.html" accesskey="u" rel="up">General</a> &nbsp; [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
195 </div>
196
197
198
199 </body>
200 </html>