source: project/bb/bb.html @ 3

Last change on this file since 3 was 3, checked in by felix winkelmann, 14 years ago

udp/test-infrastructure changes; added futures

File size: 50.0 KB
Line 
1<html><head><title>Eggs Unlimited - bb</title>
2<style type="text/css">
3  <!--
4      CODE {
5             color: #666666;
6           }
7      EM {
8           font-weight: bold;
9           font-style: normal;
10         }
11      DT.function { 
12                    background: #f5f5f5;
13                    color: black;
14                    padding: 0.1em;
15                    border: 1px solid #bbbaaf;
16                    font-family: monospace;
17                  }
18      PRE {
19        background: #efeee0;
20        padding: 0.1em;
21        border: 1px solid #bbbaaf;
22      }
23    -->
24</style></head>
25<body>
26
27<center><img src="egg.jpg"></center>
28<center><a href="http://www.call-with-current-continuation.org/eggs/index.html">back</a></center>
29
30<h2>bb</h2>
31
32<h3>Description:</h3>
33A very simple GUI toolkit based on <a href="http://www.fltk.org/">FLTK</a>.
34This extension library has been tested with FLTK versions 1.1.4 and 1.1.6.
35
36<h3>Author:</h3>
37<a href="mailto:felix@call-with-current-continuation.org">felix</a>
38
39<h3>Version:</h3>
40<ul>
41<li>1.16
42Fixed several bugs in property-getting code [Thanks to John]
43<li>1.15
44Fixed bug in <code>bb:show</code> [Thanks to Markus H&ouml;smann]
45<li>1.14
46The implicit-exit-handler didn't take previously installed exit-handlers into account (which could give
47problems when embedding); Fixed bug in <code>bb:show</code> related to embedded use
48<li>1.13
49Invalid property values could result in unbound recursion
50<li>1.12
51The <code>selection</code> property of a <code>text-editor</code> widgets can be set, now;
52Some bugfixes in callback-removal
53<li>1.11
54<code>bb:remove!</code> allows completely clearing a list widget by passing the index <code>#t</code>;
55destroying widgets removes all registered callbacks from children as well.
56<li>1.10
57Fixed setting <code>text-color</code> for the <code>tree</code> widget. Added support for Windows.
58<li>1.9
59<code>bb:remove!</code> allows destroying all types of widgets; <code>bb:show</code>
60had to be marked as callback; fixed bugs in selection-retrieval and special key-event handling
61<li>1.8
62Sergey Khorev added the <code>table</code> and <code>html-view</code> widgets
63<li>1.7
64Added <code>text-editor</code> widget
65<li>1.6
66Fixed bug in the setup script
67<li>1.5
68More widgets added by Sergey
69<li>1.4
70Sergey Khorev added support for custom event handlers
71<li>1.3
72Adapted to new FFI macro names
73<li>1.2
74Converted to new extension scheme; fixed a bug in <code>bb:get</code> (Thanks to Daniel B. Faken)
75<li>1.1
76Added <code>bb:init</code> and <code>bb:set-menu-item-active!</code> and fixed a bug in <code>bb:property</code>.
77<br>It is now required to call <code>bb:init</code> before using any other bb procedure.
78<li>1.0
79</ul>
80
81<h3>Usage:</h3>
82<pre>(require-extension bb)
83</pre>
84
85<h3>Download:</h3>
86<a href="http://www.call-with-current-continuation.org/eggs/bb.egg">bb.egg</a>
87
88<h3>Documentation:</h3>
89
90<ul>
91<li><b><i>Base interface</i></b>
92
93<dl>
94<dt><pre><b>[procedure] (bb:init [SCHEME])</b></pre>
95<dd>Iitializes the toolkit. The optional argument <code>SCHEME</code> may be a string naming
96a particular graphical scheme (possible values <code>"none"</code> or <code>"plastic"</code>)
97or <code>#f</code> (meaning the default). Calling this procedure a subsequent time has no effect.
98
99<dt><pre><b>[procedure] (bb:widget? X)</b></pre>
100</dt><dd>Returns <code>#t</code> if <code>X</code> is a widget, or <code>#f</code> otherwise.
101
102</dd><dt><pre><b>[procedure] (bb:make-widget TYPE [W H])
103[procedure] (bb:make-widget TYPE X Y W H)</b></pre>
104</dt><dd>Creates and returns a widget of the type given by the symbol <code>TYPE</code>.
105Possible widget types are:
106
107<ul>
108<li><pre>window</pre>  a normal top-level window
109</li><li><pre>double-window</pre> a double-buffered window
110</li><li><pre>button</pre>
111</li><li><pre>return-button</pre>
112</li><li><pre>choice-button</pre>
113</li><li><pre>menu-button</pre>
114</li><li><pre>check-box</pre>
115</li><li><pre>entry</pre>  a single-line text field
116</li><li><pre>edit</pre>  a multiline text field
117</li><li><pre>text-editor</pre> a full text editor with scroll bars
118</li><li><pre>int-entry
119float-entry</pre> text field for editing integer or float numbers. Although their value is a string rather than number.
120</li><li><pre>counter</pre>  a "spin-box" like widget
121</li><li><pre>dial</pre>  a "clock"-type dial widget
122</li><li><pre>clock</pre> a proper clock
123</li><li><pre>label</pre>
124</li><li><pre>slider</pre>
125</li><li><pre>adjuster</pre>  a widget for changing a value by dragging
126</li><li><pre>roller</pre>  another adjuster-like widget
127</li><li><pre>list</pre>  a vertical list of strings
128</li><li><pre>radio-button</pre>
129</li><li><pre>progress</pre>
130</li><li><pre>tabs</pre>  a collection of tab widgets
131</li><li><pre>tile</pre>  groups widgets with draggable boundaries
132</li><li><pre>pack</pre>  packs widgets vertically or horizontally
133</li><li><pre>group</pre>  a generic grouping widget
134</li><li><pre>scroll</pre>  a group widget with scrollable contents
135</li><li><pre>light-button</pre>  like a checkbox with a "light"
136</li><li><pre>menu-bar</pre>
137</li><li><pre>glwindow</pre> a window that contains OpenGL graphics
138</li><li><pre>live-image</pre> an image that will be redrawn from a given pointer
139</li><li><pre>tree</pre> a tree control. Available only if bb was compiled with a <a href="http://www.osc.edu/~jbryan/FLU">FLU</a> support.
140</li><li><pre>table</pre> a simple table widget
141</li><li><pre>html-view</pre> a simple html viewer
142</li></ul>
143
144<p>A top-level window created with <code>bb:make-widget</code> will not automatically be shown until
145<code>bb:show</code> has been called.
146
147</p></dd><dt><pre><b>[procedure] (bb:property WIDGET PROPERTY)
148[setter] (set! (bb:property WIDGET PROPERTY) VALUE)</b></pre>
149</dt><dd>Gets or sets the properties given in <code>PROPERTY1 ...</code> (which should be symbols).
150Values may also be lists, in that case the values are combined (this only applies to certain properties - see below).
151<p>Some properties may be set for individual items of the <code>tree</code> and <code>table</code> widgets.
152They are specified in the form <code>(list WIDGET ITEMID)</code>.
153<code>ITEMID</code> is either unique item id or one of the symbols:
154<dl><dt><pre>root
155connector
156leaf
157branch</pre>In this case the <code>VALUE</code> will be applied either to root node, connector or
158all subsequent branches or leaves added to the tree.<br>
159<code>width</code> and <code>align</code> properties can be applied to the <code>table</code>
160widget's columns.
161</dl></dt></p>
162
163<p>Allowed widget properties are:
164
165</p><dl><dt><pre>x
166y
167width
168height</pre>
169</dt><dd>Position and dimensions (integer). Positions are always relative to the container.
170<code>Width</code> property may be set for <code>connector</code> item of the <code>tree</code> widget.
171
172
173</dd><dt><pre>text</pre>
174</dt><dd>The text of a label, button, text-fields or <code>html-view</code>. Also the title of a window.
175For the <code>tree</code> widget the value is the label of the subitem. For the <code>table</code>
176widget one can specify individual cells in the form <code>(list TABLEWIDGET ROW COLUMN)</code>
177The negative <code>ROW</code> means column header.
178
179</dd><dt><pre>value</pre>
180</dt><dd>The value of a "range" widget (<code>slider, roller, adjuster, counter</code> or <code>dial</code>),
181in which case it should be a number. For <code>check-box</code> and <code>radio-button</code> widgets
182the value should be a boolean. For <code>list</code> widgets, the value is the index of the highlighted
183item, starting from 1. The value of the <code>choice-button</code> widget is the index of the selected
184item. For <code>tree</code> widgets, the value is the unique id of the currently selected item. The value
185of the <code>html-view</code> is a current file name.
186
187</dd><dt><pre>box</pre>
188</dt><dd>The <i>box type</i>. A box type is one of the symbols
189<pre>no-box
190flat-box
191up-box
192down-box
193up-frame
194down-frame
195thin-up-box
196thin-down-box
197thin-up-frame
198thin-down-frame
199engraved-box
200embossed-box
201engraved-frame
202embossed-frame
203border-box
204</pre>
205
206</dd><dt><pre>callback</pre>
207</dt><dd>The callback procedure that is invoked when the value of a widget changes. See the <code>when</code>
208property for more information. For <code>tree</code> widgets one can obtain additional information
209from properties <code>callback-reason</code> and <code>callback-node</code>.
210
211</dd><dt><pre>image</pre>
212</dt><dd>An image that should be drawn into the widget. See <code>bb:image</code> for how to load images.
213You can also set the value <code>image</code> property to a string, which will load any image file with this
214name automatically. The value may also be a pointer object pointing to a data buffer for a <code>live-image</code>
215widget. Images may be set for a <code>tree</code> widget items.
216If subitem is the <code>branch</code> or <code>connector</code>, then <code>VALUE</code>
217can specify pair of the images: for closed and open state respectively.
218
219</dd><dt><pre>type</pre>
220</dt><dd>The <i>type</i> of a widget. The possible type symbols depend on what kind of widget it applies to:
221
222<ul>
223<li><pre>scroll</pre>
224<pre>scroll-horizontal
225scroll-vertical
226scroll-both
227scroll-always-on
228scroll-horizontal-always
229scroll-vertical-always
230scroll-both-always
231</pre>
232
233(may be combined)
234</li><li><pre>slider</pre>
235<pre>vertical-fill-slider
236horizontal-fill-slider
237vertical-nice-slider
238horizontal-nice-slider
239</pre>
240</li><li><pre>dial</pre>
241<pre>normal-dial
242line-dial
243fill-dial
244</pre>
245</li></ul>
246
247</dd><dt><pre>resizable
248modal</pre>
249</dt><dd>Whether a window is resizable and/or modal.
250
251</dd><dt><pre>direction</pre>
252</dt><dd>The direction of a widget, which should be one of the symbols <code>horizontal</code> or <code>vertical</code>.
253
254</dd><dt><pre>color</pre>
255</dt><dd>The background color of a widget. This can either be a value returned by <code>bb:rgb</code> or one of the
256following symbols:
257
258<pre>gray0
259dark3
260dark2
261dark1
262light1
263light2
264light3
265gray
266black
267red
268green
269yellow
270blue
271magenta
272cyan
273dark-red
274dark-green
275dark-yellow
276dark-blue
277dark-magenta
278dark-cyan
279white
280</pre>
281
282<p>The color attribute of a <code>live-image</code> widget designates the number of color channels (1-4).
283Also is applicable to the <code>connector</code> subitem of the <code>tree</code> widget.
284
285</p></dd><dt><pre>image-width
286image-height</pre>
287</dt><dd>The width and height of a <code>live-image</code> widget.
288
289</dd><dt><pre>focus</pre>
290</dt><dd>Whether this widget has the input focus. Calling <code>bb:property</code> for this property will
291always return 0 (but setting it will change the focus to the target widget).
292
293</dd><dt><pre>spacing</pre>
294</dt><dd>The spacing inside group widgets (in pixels).
295
296</dd><dt><pre>maximum
297minimum</pre>
298</dt><dd>Maximum and minimum values for range widgets.
299
300</dd><dt><pre>x-position
301y-position</pre>
302</dt><dd>X- and Y-position for <code>scroll</code> widgets.
303
304</dd><dt><pre>text-color
305text-size</pre>
306</dt><dd>Text color and size. Also can be applied to the <code>tree</code> subitems.
307
308</dd><dt><pre>text-font</pre>
309</dt><dd>Text font, which may be one of the following:
310
311<pre>helvetica
312helvetica-bold
313helvetica-italic
314helvetica-bold-italic
315courier
316courier-bold
317courier-italic
318courier-bold-italic
319times
320times-bold
321times-italic
322times-bold-italic
323symbol
324screen
325screen-bold
326</pre>
327Can be specified for the <code>tree</code> branches and leaves.
328
329</dd><dt><pre>selection-color</pre>
330</dt><dd>The color of the selection in a text widget or the color of indicators in other widgets.
331
332</dd><dt><pre>position</pre>
333</dt><dd>The position of the caret in an <code>entry</code>, <code>edit</code> or <code>text-editor</code> widget. Setting the position
334to <code>-1</code> will move the caret to the end of the current text.
335
336</dd><dt><pre>mark</pre>
337</dt><dd>The position of the selection mark in an <code>entry</code>, <code>edit</code> or <code>text-editor</code> widget. The text
338between the selection mark and the caret is the current selection.
339
340</dd><dt><pre>selection</pre>
341</dt><dd>The currently selected text in an <code>entry</code>, <code>edit</code> or <code>text-editor</code> widget.
342When set, the value should be a pair containing start and end position of the selection in the buffer.
343
344</dd><dt><pre>tooltip</pre>
345</dt><dd>A string that should be displayed, when the mouse hovers over a widget.
346
347</dd><dt><pre>visible</pre>
348</dt><dd>Whether a widget is visible or not.
349
350</dd><dt><pre>resizable-widget</pre>
351</dt><dd>The widget in a group, which should be exclusively resizable.
352
353</dd><dt><pre>valid-context</pre>
354</dt><dd>A flag indicating whether the GL context for an <code>glwindow</code> is already initialized.
355
356</dd><dt><pre>read-only</pre>
357</dt><dd>If true, an <code>edit</code> or <code>entry</code> widget can not be changed by the user.
358
359</dd><dt><pre>align</pre>
360</dt><dd>The alignment of the widget label. May be combination of the following symbols:
361<pre>center
362top
363bottom
364left
365right
366inside
367text-over-image
368image-over-text
369clip
370wrap</pre>
371
372</dd><dt><pre>when</pre>
373</dt><dd>An indicator when a widgets callback should be invoked. The default behaviour depends on the type of the
374widget. Possible settings are:
375
376<ul>
377<li><pre>never</pre> never invoked the callback
378</li><li><pre>changed</pre> when the widget's value changes
379</li><li><pre>released</pre> when the button or key is released and the value changes
380</li><li><pre>enter</pre> when the enter key is pressed and the value changes
381</li><li><pre>always</pre> modifier for <code>released</code> or <code>enter</code>, that indicates the callback should
382  be invoked, even if the value doesn't change
383</li></ul>
384
385<p>The default behaviour is to invoke the callback whenever the value of a widget changes, when a
386<code>window</code> is closed, when <code>glwindow</code> needs to be redrawn, or a <code>button</code>
387or <code>list</code> item has been clicked.
388</p></dd>
389
390</dd><dt><pre>handler</pre>
391</dt><dd>The callback procedure that is invoked when the event occurs. The event is passed in a
392first (and only) argument to the handler. A event is one of the symbols:
393<pre>no-event
394push
395release
396enter
397leave
398drag
399focus
400unfocus
401keydown
402keyup
403close
404move
405shortcut
406deactivate
407activate
408hide
409show
410paste
411selectionclear
412mousewheel
413dnd-enter
414dnd-drag
415dnd-leave
416dnd-release
417unknown</pre>
418<p>Additional information about event can be obtained with <code>bb:event</code> procedure.
419Returning <code>#f</code> from handler indicates that widget is not interested in handling
420this event. <code>#t</code> means that event was successfully handled. Any other value leads to
421invoking default handler of this widget.<br>
422The <code>html-view</code> widget's <code>handler</code> is invoked when user tries to follow
423the link (which URI is passed as an argument). <code>Handler</code> should return either the name
424of the temporary file or <code>#f</code> and set the <code>text</code> property.
425</p>
426</dd><dt><pre>callback-reason</pre>
427</dt><dd>The reason for callback. Available only for <code>tree</code> widget. Valid values are:
428<pre>hilighted
429unhilighted
430selected
431unselected
432opened
433closed
434double-click
435widget-callback
436moved-node
437new-node
438nothing</pre>
439</dd><dt><pre>callback-node</pre>
440</dt><dd>The unique id of the node that caused callback. Available only for <code>tree</code> widget.
441</dd>
442</dl>
443
444</p></dd><dt><pre><b>[procedure] (bb:event PROPERTY)
445[setter] (set! (bb:event PROPERTY) VALUE)</b></pre>
446</dt><dd>Gets or sets the event properties given in <code>PROPERTY</code> (which should be symbol).
447Only <code>click?</code> and <code>clicks</code> properties can be set.
448
449<p>Allowed event properties are:
450
451</p><dl><dt><pre>alt
452ctrl
453shift
454click?
455button1
456button2
457button3</pre>
458</dt><dd>Whether mouse or special keyboard button was pressed.
459
460</dd><dt><pre>clicks</pre>
461</dt><dd>The number of clicks (<code>N - 1</code> for <code>N</code> clicks)
462
463</dd><dt><pre>x
464y
465x-root
466y-root
467dx
468dy</pre>
469</dt><dd>Coordinates.
470
471</dd><dt><pre>length
472text</pre>
473</dt><dd>The length and text.
474
475</dd><dt><pre>key</pre>
476</dt><dd>Which key was pressed. Possible values are:
477<ul>
478<li><p>character - for ordinary keys
479</p></li><li><p>the pair of character and 'kp - for keypad keys
480</p></li><li><pre>backspace
481tab
482enter
483pause
484scroll-lock
485escape
486home
487left
488up
489right
490down
491page-up
492page-down
493end
494print
495insert
496menu
497help
498num-lock
499shift-l
500shift-r
501control-l
502control-r
503caps-lock
504meta-l
505meta-r
506alt-l
507alt-r
508delete
509F1...F24
510button1
511button2
512button3
513unknown
514</pre>for special keys
515</li></ul>
516
517</dd></dl>
518
519</dd><dt><pre><b>[procedure] (bb:message MESSAGE)
520[procedure] (bb:message TYPE MESSAGE [BUTTON1 [BUTTON2 [BUTTON3]]])</b></pre>
521</dt><dd>Shows a message box of type <code>TYPE</code> with the string <code>MESSAGE</code>.
522The optional <code>BUTTON</code> arguments should be strings the specify the text of any
523extra buttons. Message types may be
524
525<ul>
526<li><pre>message</pre> information dialog with an "OK" button.
527</li><li><pre>alert</pre> alert box with an "OK" button.
528</li><li><pre>ask</pre> a "yes/no" request dialog.
529</li><li><pre>choice</pre> a request button with three choices.
530</li></ul>
531
532</dd><dt><pre><b>[procedure] (bb:run [WAIT])</b></pre>
533</dt><dd>Processes events. If <code>WAIT</code> is true or not specified, <code>bb:run</code> does
534not return until the last window closes. If <code>WAIT</code> is a number, then <code>bb:run</code>
535returns after that many seconds, or earlier, if no events are queued.
536
537</dd><dt><pre><b>[procedure] (bb:add! WIDGET ITEM [CALLBACK [SHORTCUT]])
538[procedure] (bb:add! LISTWIDGET TEXT [POSITION])
539[procedure] (bb:add! TREEWIDGET TEXT [PARENT [POSITION [SUBWIDGET]])
540[procedure] (bb:add! TABLEWIDGET [CELLTEXT ...])</b></pre>
541</dt><dd>If <code>WIDGET</code> is a <code>menu-bar</code>, <code>choice-button</code> or
542<code>menu-button</code>, <code>bb:add!</code> adds a new menu with the text
543<code>ITEM</code> (a string), the keyboard-shortcut <code>SHORTCUT</code> (another string) and the callback
544<code>CALLBACK</code> (a procedure of no arguments).
545<br>The string encoding the menu-item can include subitems, using the syntax <code>foo/bar/baz</code>. As many
546levels as necessary are created.
547<br>The shortcut can be <code>#f</code> or a string describing the shortcut in one of two ways: <code>[#+^]ASCII</code>
548or <code>[#+^]CHAR</code> where a decimal value represents an ascii character (eg. 97 is the ascii for 'a'), and the
549optional prefixes enhance the value that follows. Multiple prefixes must appear in the above order.
550
551<p><table border="1">
552<tbody><tr><th><code>#</code></th><td>Alt
553</td></tr><tr><th><code>+</code></th><td>Shift
554</td></tr><tr><th><code>^</code></th><td>Control
555</td></tr></tbody></table>
556
557</p><p>If <code>WIDGET</code> is an <code>edit</code>,
558<code>entry</code> or <code>text-edit</code> widget, <code>ITEM</code>
559should be a string, which will be added to the end of the existing text.
560
561</p><p>If <code>WIDGET</code> is a <code>list</code>, the <code>ITEM</code> should be a string, which will added to the list
562of existing lines. The string may be prefixed by
563a <code>@...</code> sequence to enable special formatting:
564
565</p><p><table border="1">
566<tbody><tr><th><code>@.</code></th><th>Print rest of line, don't look for more '@' signs
567</th></tr><tr><th><code>@@</code></th><th>Print rest of line starting with '@'
568</th></tr><tr><th><code>@l</code></th><th>Use a large (24 point) font
569</th></tr><tr><th><code>@m</code></th><th>Use a medium large (18 point) font
570</th></tr><tr><th><code>@s</code></th><th>Use a small (11 point) font
571</th></tr><tr><th><code>@b</code></th><th>Use a bold font
572</th></tr><tr><th><code>@i</code></th><th>Use an italic font
573</th></tr><tr><th><code>@f or @t</code></th><th> Use a fixed-pitch font
574</th></tr><tr><th><code>@c</code></th><th>Center the line horizontally
575</th></tr><tr><th><code>@r</code></th><th>Right-justify the text
576</th></tr><tr><th><code>@B0, @B1, ... @B255</code></th><th> Fill the backgound with indexed color
577</th></tr><tr><th><code>@C0, @C1, ... @C255</code></th><th> Use indexed color to draw the text
578</th></tr><tr><th><code>@F0, @F1, ...</code></th><th> Use indexed font to draw the text
579</th></tr><tr><th><code>@S1, @S2, ...</code></th><th> Use point size n to draw the text
580</th></tr><tr><th><code>@u or @_</code></th><th>Underline the text.
581</th></tr><tr><th><code>@-</code></th><th>draw an engraved line through the middle.
582</th></tr></tbody></table>
583
584</p><p>If <code>WIDGET</code> is a widget of any
585other type, then <code>ITEM</code> should be a child widget, which will be added with <code>WIDGET</code>
586as its parent.
587
588</p><p>For <code>tree</code> widget <code>TEXT</code> can be either full path (items are separated with slash)
589or text label. If it is terminated with slash, the branch (rather than leaf) will be inserted. One can
590specify parent node id and position in it (default values are <code>-1</code> for both).
591The <code>SUBWIDGET</code> is a widget that will be inserted as a node. The procedure returns either
592the unique id of the freshly inserted node or <code>-1</code> if failed.
593</p><p>This procedure can be used to add either columns
594(if first <code>CELLTEXT</code> is symbol <code>column</code>) or cells to the <code>table</code> widget.
595
596</p></dd><dt><pre><b>[procedure] (bb:image X)
597[procedure] (bb:image PTR W H D)</b></pre>
598</dt><dd>If <code>X</code> is a string, then <code>bb:image</code> will load an image file
599(if its format is supported by FLTK). If <code>X</code> is a pointer, then it is treated as a pointer to XPM data.
600The 4-argument form of <code>bb:image</code> creates an RGB image from the data pointed to by the foreign pointer
601<code>PTR</code>, with width <code>W</code>, height <code>H</code> and depth <code>D</code>, where <code>D</code>
602specifies the number of color channels (1-4).
603
604</dd><dt><pre><b>[procedure] (bb:image-data IMAGE)</b></pre>
605</dt><dd>Returns four values: list of pointers to <code>IMAGE</code> data (usually one element for all formats,
606except of pixmaps), width, height and depth of the <code>IMAGE</code>.
607
608</dd><dt><pre><b>[procedure] (bb:remove! WIDGET [INDEX])</b></pre>
609</dt><dd>Removes the entry at the position <code>INDEX</code> from the <code>list</code> <code>WIDGET</code>,
610or all items, if index is <code>#t</code>. If <code>widget</code> is an image pointer, the storage occupied by the image will be released.
611For <code>tree</code> <code>WIDGET</code> the node with id <code>INDEX</code> will be removed.
612Destroys the widget.
613
614</dd><dt><pre><b>[procedure] (bb:set-menu-item-active! WIDGET INDEX FLAG)</b></pre>
615</dt><dd>Activates or deactivates the menu item with the index <code>INDEX</code> in the menu-bar <code>WIDGET</code>,
616depending on the boolean <code>FLAG</code>. Counting menu-items starts with 0 and every sub-menu increases the count by one.
617Note that each sub-menu introduces an invisible extra menu-item that has to be counted in.
618
619</dd><dt><pre><b>[procedure] (bb:redraw WIDGET)</b></pre>
620</dt><dd>Redraws <code>WIDGET</code>.
621
622</dd><dt><pre><b>[procedure] (bb:show WINDOW [ARG ...])</b></pre>
623</dt><dd>Shows <code>WINDOW</code>. If <code>WINDOW</code> is already visible, it will be raised to the top.
624<code>ARG</code>s are the options to be parsed by FLTK. By default the name of the executable is passed.
625<code>#f</code> doesn't pass any arguments.
626
627</dd><dt><pre><b>[procedure] (bb:select-file MESSAGE PATTERN [FILENAME])</b></pre>
628</dt><dd>Opens a file-dialog and returns the selected filename (or <code>#f</code> if the file-selection has been canceled).
629<code>PATTERN</code> is a file-pattern that is used to match filenames
630that can be selected. The following syntax is used by pattern:
631
632<ul>
633<li><code>*</code> matches any sequence of 0 or more characters.
634</li><li><code>?</code> matches an<y single="" character=""></y></li><li><code>[set]</code>
635matches any character in the set. Set can contain any single
636characters, or a-z to represent a range. To match ] or - they must be
637the first characters. To match ^ or ! they must not be the first
638characters.
639</li><li><code>[^set]</code> or <code>[!set]</code> matches any character not in the set.
640</li><li><code>{X|Y|Z}</code> or <code>{X,Y,Z}</code> matches any one of the subexpressions literally.
641</li><li><code>\x</code> quotes the character x so it has no special meaning.
642</li><li><code>x</code> all other characters must be matched exactly.
643</li></ul>
644
645<code>FILENAME</code> specifies the default filename, if given.
646
647</dd><dt><pre><b>[procedure] (bb:select-color [STRING])
648[procedure] (bb:select-color COLOR [STRING])</b></pre>
649</dt><dd>Pops up a color-selection dialog. If <code>COLOR</code> is an exact integer, or a symbol naming one of the
650default colors, then the user can select a color index, which will then be returned. If <code>COLOR</code> is
651a three-element list or vector, then the user can select an RGB (or HSV) color. <code>bb:select-color</code> either
652returns a color value (an integer, encoding a color index or a packed RGB value), or <code>#f</code> if the
653selection dialog was closed or canceled.
654
655</dd><dt><pre><b>[procedure] (bb:rgb R [G B])</b></pre>
656</dt><dd>Transforms the red, green and blue components given in <code>R, G</code> and <code>B</code> into a color
657value. All components should be integers in the range 0 - 255. If <code>G</code> and <code>B</code> are
658not given, <code>bb:rgb</code> returns a list of the red, green and blue color components of the packed color value
659<code>R</code>.
660
661</dd><dt><pre><b>[procedure] (bb:get-input LABEL [DEFAULT])</b></pre>
662</dt><dd>Pops up a dialog the requests an input string. <code>LABEL</code> should be a string that will be shown
663in the dialog, <code>DEFAULT</code> is the default text.
664
665</dd><dt><pre><b>[procedure] (bb:group WIDGET THUNK)</b></pre>
666</dt><dd>Invokes the zero-argument procedure <code>THUNK</code> in a dynamic context in which all created widgets
667are added the group <code>WIDGET</code> (which should be a <code>window, group, tabs, tile, pack</code> or
668<code>scroll</code>).
669
670</dd></dl>
671
672<p>Here a list of keyboard shortcuts usable in <code>entry</code> and <code>edit</code> widgets:
673
674</p><center><table border="1" width="90%" summary="Fl_Input keyboard and mouse bindings.">
675
676<tbody><tr><td width="200"><b>Mouse button 1</b></td><td>Moves the cursor to
677 this point. Drag selects characters.  Double click selects words.
678 Triple click selects all text.  Shift+click extends the selection.
679 When you select text it is automatically copied to the clipboard.
680</td></tr>
681
682<tr><td><b>Mouse button 2</b></td><td>Insert the clipboard at
683the point clicked.  You can also select a region and replace it with the
684clipboard by selecting the region with mouse button 2.
685</td></tr>
686
687<tr><td><b>Mouse button 3</b></td><td>Currently acts like button 1.</td></tr>
688
689<tr><td><b>Backspace</b></td><td>Deletes one character to the left, or
690deletes the selected region.</td></tr>
691<tr><td><b>Enter</b></td><td>May cause the callback, see the <code>when</code> property.</td></tr>
692<tr><td><b>^A or Home</b></td><td>Go to start of line.</td></tr>
693
694<tr><td><b>^B or Left</b></td><td>Move left</td></tr>
695<tr><td><b>^C</b></td><td>Copy the selection to the clipboard</td></tr>
696<tr><td><b>^D or Delete</b></td><td>Deletes one character to the right
697or deletes the selected region.</td></tr>
698<tr><td><b>^E or End</b></td><td>Go to the end of line.</td></tr>
699<tr><td><b>^F or Right</b></td><td>Move right</td></tr>
700<tr><td><b>^K</b></td><td>Delete to the end of line (next \n character)
701or deletes a single \n character.  These deletions are all concatenated
702into the clipboard.</td></tr>
703
704<tr><td><b>^N or Down</b></td><td>Move down (<code>edit</code> widget
705only, otherwise it moves to the next input field).</td></tr>
706<tr><td><b>^P or Up</b></td><td>Move up (for <code>edit</code> widgets only,
707otherwise it moves to the previous input field).</td></tr>
708<tr><td><b>^U</b></td><td>Delete everything.</td></tr>
709<tr><td><b>^V or ^Y</b></td><td>Paste the clipboard</td></tr>
710<tr><td><b>^X or ^W</b></td><td>Copy the region to the clipboard and
711delete it.</td></tr>
712<tr><td><b>^Z or ^_</b></td><td>Undo.  This is a single-level undo
713mechanism, but all adjacent deletions and insertions are concatenated
714into a single "undo".  Often this will undo a lot more than you
715expected.</td></tr>
716
717<tr><td><b>Shift+move</b></td><td>Move the cursor but also extend the
718selection.</td></tr>
719
720<tr><td><b>RightCtrl or
721<br>Compose</b></td><td><a name="compose">Start</a>
722a compose-character
723sequence.  The next one or two keys typed define the character to
724insert (see table that follows.)
725
726<p>For instance, to type "á" type [compose][a]['] or [compose]['][a].
727
728</p><p>The character "nbsp" (non-breaking space) is typed by using
729[compose][space].
730
731</p><p>The single-character sequences may be followed by a space if
732necessary to remove ambiguity.  For instance, if you really want to
733type "ª~" rather than "ã" you must type [compose][a][space][~].
734
735</p><p>The same key may be used to "quote" control characters into the
736text.  If you need a <tt>^Q</tt> character you can get one by typing
737[compose][Control+Q].
738
739
740</p><p>X may have a key on the keyboard
741defined as <tt>XK_Multi_key</tt>.  If so this key may be used as well
742as the right-hand control key.  You can set this up with the program
743<tt>xmodmap</tt>.
744
745</p><p>If your keyboard is set to support a foreign language you should
746also be able to type "dead key" prefix characters.  On X you will
747actually be able to see what dead key you typed, and if you then move
748the cursor without completing the sequence the accent will remain
749inserted.
750</p></td></tr></tbody></table></center>
751<center><table border="1" summary="Character Composition Table">
752<caption align="top">Character Composition Table</caption>
753<tbody><tr>
754        <th>Keys</th><th>Char</th>
755
756        <th>Keys</th><th>Char</th>
757        <th>Keys</th><th>Char</th>
758        <th>Keys</th><th>Char</th>
759        <th>Keys</th><th>Char</th>
760        <th>Keys</th><th>Char</th>
761
762</tr><tr>
763        <td align="center"><tt>sp</tt></td><td align="center"><small>nbsp</small></td>
764        <td align="center"><tt>*</tt></td><td align="center">°</td>
765        <td align="center"><tt>` A</tt></td><td align="center">À</td>
766        <td align="center"><tt>D -</tt></td><td align="center">Ð</td>
767
768        <td align="center"><tt>` a</tt></td><td align="center">à</td>
769        <td align="center"><tt>d -</tt></td><td align="center">ð
770</td></tr><tr>
771        <td align="center"><tt>!</tt></td><td align="center">¡</td>
772        <td align="center"><tt>+ -</tt></td><td align="center">±</td>
773        <td align="center"><tt>' A</tt></td><td align="center">Á</td>
774
775        <td align="center"><tt>~ N</tt></td><td align="center">Ñ</td>
776        <td align="center"><tt>' a</tt></td><td align="center">á</td>
777        <td align="center"><tt>~ n</tt></td><td align="center">ñ
778</td></tr><tr>
779        <td align="center"><tt>%</tt></td><td align="center">¢</td>
780        <td align="center"><tt>2</tt></td><td align="center">²</td>
781
782        <td align="center"><tt>A ^</tt></td><td align="center">Â</td>
783        <td align="center"><tt>` O</tt></td><td align="center">Ò</td>
784        <td align="center"><tt>^ a</tt></td><td align="center">â</td>
785        <td align="center"><tt>` o</tt></td><td align="center">ò
786</td></tr><tr>
787        <td align="center"><tt>#</tt></td><td align="center">£</td>
788
789        <td align="center"><tt>3</tt></td><td align="center">³</td>
790        <td align="center"><tt>~ A</tt></td><td align="center">Ã</td>
791        <td align="center"><tt>' O</tt></td><td align="center">Ó</td>
792        <td align="center"><tt>~ a</tt></td><td align="center">ã</td>
793        <td align="center"><tt>' o</tt></td><td align="center">ó
794
795</td></tr><tr>
796        <td align="center"><tt>$</tt></td><td align="center"></td>
797        <td align="center"><tt>'</tt></td><td align="center">Ž</td>
798        <td align="center"><tt>: A</tt></td><td align="center">Ä</td>
799        <td align="center"><tt>^ O</tt></td><td align="center">Ô</td>
800
801        <td align="center"><tt>: a</tt></td><td align="center">ä</td>
802        <td align="center"><tt>^ o</tt></td><td align="center">ô
803</td></tr><tr>
804        <td align="center"><tt>y =</tt></td><td align="center">¥</td>
805        <td align="center"><tt>u</tt></td><td align="center">µ</td>
806        <td align="center"><tt>* A</tt></td><td align="center">Å</td>
807
808        <td align="center"><tt>~ O</tt></td><td align="center">Õ</td>
809        <td align="center"><tt>* a</tt></td><td align="center">å</td>
810        <td align="center"><tt>~ o</tt></td><td align="center">õ
811</td></tr><tr>
812        <td align="center"><tt>|</tt></td><td align="center">Š</td>
813        <td align="center"><tt>p</tt></td><td align="center"></td>
814
815        <td align="center"><tt>A E</tt></td><td align="center">Æ</td>
816        <td align="center"><tt>: O</tt></td><td align="center">Ö</td>
817        <td align="center"><tt>a e</tt></td><td align="center">æ</td>
818        <td align="center"><tt>: o</tt></td><td align="center">ö
819</td></tr><tr>
820        <td align="center"><tt>&amp;</tt></td><td align="center">§</td>
821
822        <td align="center"><tt>.</tt></td><td align="center">·</td>
823        <td align="center"><tt>, C</tt></td><td align="center">Ç</td>
824        <td align="center"><tt>x</tt></td><td align="center">×</td>
825        <td align="center"><tt>, c</tt></td><td align="center">ç</td>
826        <td align="center"><tt>- :</tt></td><td align="center">÷
827
828</td></tr><tr>
829        <td align="center"><tt>:</tt></td><td align="center">š</td>
830        <td align="center"><tt>,</tt></td><td align="center">ž</td>
831        <td align="center"><tt>E `</tt></td><td align="center">È</td>
832        <td align="center"><tt>O /</tt></td><td align="center">Ø</td>
833
834        <td align="center"><tt>` e</tt></td><td align="center">è</td>
835        <td align="center"><tt>o /</tt></td><td align="center">ø
836</td></tr><tr>
837        <td align="center"><tt>c</tt></td><td align="center">©</td>
838        <td align="center"><tt>1</tt></td><td align="center">¹</td>
839        <td align="center"><tt>' E</tt></td><td align="center">É</td>
840
841        <td align="center"><tt>` U</tt></td><td align="center">Ù</td>
842        <td align="center"><tt>' e</tt></td><td align="center">é</td>
843        <td align="center"><tt>` u</tt></td><td align="center">ù
844</td></tr><tr>
845        <td align="center"><tt>a</tt></td><td align="center">ª</td>
846        <td align="center"><tt>o</tt></td><td align="center">º</td>
847
848        <td align="center"><tt>^ E</tt></td><td align="center">Ê</td>
849        <td align="center"><tt>' U</tt></td><td align="center">Ú</td>
850        <td align="center"><tt>^ e</tt></td><td align="center">ê</td>
851        <td align="center"><tt>' u</tt></td><td align="center">ú
852</td></tr><tr>
853        <td align="center"><tt>&lt; &lt;</tt></td><td align="center">«</td>
854
855        <td align="center"><tt>&gt; &gt;</tt></td><td align="center">»</td>
856        <td align="center"><tt>: E</tt></td><td align="center">Ë</td>
857        <td align="center"><tt>^ U</tt></td><td align="center">Û</td>
858        <td align="center"><tt>: e</tt></td><td align="center">ë</td>
859        <td align="center"><tt>^ u</tt></td><td align="center">û
860
861</td></tr><tr>
862        <td align="center"><tt>~</tt></td><td align="center">¬</td>
863        <td align="center"><tt>1 4</tt></td><td align="center">Œ</td>
864        <td align="center"><tt>` I</tt></td><td align="center">Ì</td>
865        <td align="center"><tt>: U</tt></td><td align="center">Ü</td>
866
867        <td align="center"><tt>` i</tt></td><td align="center">ì</td>
868        <td align="center"><tt>: u</tt></td><td align="center">ü
869</td></tr><tr>
870        <td align="center"><tt>-</tt></td><td align="center">­</td>
871        <td align="center"><tt>1 2</tt></td><td align="center">œ</td>
872        <td align="center"><tt>' I</tt></td><td align="center">Í</td>
873
874        <td align="center"><tt>' Y</tt></td><td align="center">Ý</td>
875        <td align="center"><tt>' i</tt></td><td align="center">í</td>
876        <td align="center"><tt>' y</tt></td><td align="center">ý
877</td></tr><tr>
878        <td align="center"><tt>r</tt></td><td align="center">®</td>
879        <td align="center"><tt>3 4</tt></td><td align="center">Ÿ</td>
880
881        <td align="center"><tt>^ I</tt></td><td align="center">Î</td>
882        <td align="center"><tt>T H</tt></td><td align="center">Þ</td>
883        <td align="center"><tt>^ i</tt></td><td align="center">î</td>
884        <td align="center"><tt>t h</tt></td><td align="center">þ
885</td></tr><tr>
886        <td align="center"><tt>_</tt></td><td align="center">¯</td>
887
888        <td align="center"><tt>?</tt></td><td align="center">¿</td>
889        <td align="center"><tt>: I</tt></td><td align="center">Ï</td>
890        <td align="center"><tt>s s</tt></td><td align="center">ß</td>
891        <td align="center"><tt>: i</tt></td><td align="center">ï</td>
892        <td align="center"><tt>: y</tt></td><td align="center">ÿ
893
894</td></tr></tbody></table></center>
895
896
897<p></p></li><li><b><i>"ASCII Picture" interface</i></b>
898
899<dl><dt><pre><b>[procedure] (bb:make-widgets SPEC WIDTH HEIGHT [CHARMAP])</b></pre>
900</dt><dd>Creates the widgets defined in the graphical representation string <code>SPEC</code> in a window of the
901dimensions <code>WIDTH</code> and <code>HEIGHT</code>.
902The graphical representation string is an ASCII picture of the widget layout, with uppercase characters designating
903widget types:
904
905<p><table border="1">
906<tbody><tr><th>B</th><td>button
907</td></tr><tr><th>C</th><td>check-xbox
908</td></tr><tr><th>E</th><td>entry
909</td></tr><tr><th>I</th><td>edit
910</td></tr><tr><th>N</th><td>counter
911</td></tr><tr><th>M</th><td>menu-bar
912</td></tr><tr><th>D</th><td>dial
913</td></tr><tr><th>S</th><td>slider
914</td></tr><tr><th>A</th><td>adjuster
915</td></tr><tr><th>L</th><td>list
916</td></tr><tr><th>W</th><td>label
917</td></tr><tr><th>O</th><td>radio-button
918</td></tr><tr><th>P</th><td>progress
919</td></tr><tr><th>T</th><td>tabs
920</td></tr><tr><th>F</th><td>glwindow
921</td></tr><tr><th>X</th><td>tile
922</td></tr><tr><th>G</th><td>group
923</td></tr><tr><th>K</th><td>pack
924</td></tr><tr><th>Z</th><td>scroll
925</td></tr><tr><th>R</th><td>roller
926</td></tr><tr><th>J</th><td>clock
927</td></tr><tr><th>V</th><td>live-image
928</td></tr><tr><th>H</th><td>choice-button
929</td></tr><tr><th>&lt;</th><td>return-button
930</td></tr><tr><th>%</th><td>int-entry
931</td></tr><tr><th>*</th><td>int-entry
932</td></tr><tr><th>&gt;</th><td>menu-button
933</td></tr><tr><th>Y</th><td>tree
934</td></tr></tbody></table>
935
936</p><p>A widgets dimensions are computed by drawing a contguous line along the upper and left border, starting from the origin
937of the widget:
938
939</p><pre>01234567890123456789
940....................
941.....BBBBBBBBB......
942.....BBBBBBBBB......
943.....BBBBBBBBB......
944....................
945</pre>
946
947Here we would have a button at 5/1, with width 9 and height 3 (before adjusting the dimensions to the specified
948width and height of the complete layout).
949
950<p><code>bb:make-widgets</code> returns an association list of the form <code>(TAG . WIDGET)</code> which maps widget-tags
951to created widgets. If the optional argument <code>CHARMAP</code> (an list of lists of the form
952<code>(ALIASCHAR CHAR TAG)</code>) is given, then any occurrence of <code>ALIASCHAR</code> in the picture is treated
953as <code>CHAR</code>. The <code>TAG</code> will be returned in the widget a-list. If <code>CHARMAP</code> is not given,
954then the tag defaults to the usual widget type character.
955
956</p><p>Specially delimited strings can be embedded in the widget pictures:
957
958</p><dl><dt><pre>"STRING"</pre>
959</dt><dd>Sets the <code>text</code> property of the widget.
960</dd><dt><pre>|STRING|</pre>
961</dt><dd>Sets the direction, box type, slider type or color of the widget. Valid values for <code>STRING</code> are:
962
963<p>direction
964</p><pre>v
965h
966</pre>
967
968<p>slider type
969</p><pre>vfill
970hfill
971vnice
972hnice
973</pre>
974
975<p>box type
976</p><pre>no
977flat
978up
979down
980thinup
981thindown
982upframe
983downframe
984thinupframe
985thindownframe
986engraved
987embossed
988engravedframe
989embossedframe
990border
991</pre>
992
993<p>color
994</p><pre>gray
995black
996red
997green
998yellow
999blue
1000magenta
1001cyan
1002darkred
1003darkgreen
1004darkyellow
1005darkblue
1006darkmagenta
1007darkcyan
1008white
1009</pre>
1010
1011</dd><dt><pre>'STRING, ...'</pre>
1012</dt><dd>Adds items to a <code>list</code> widget.
1013
1014</dd><dt><pre>#STRING#</pre>
1015</dt><dd><code>STRING</code> should be the name of an image file (as understood by <code>bb:image</code>).
1016
1017</dd><dt><pre>:STRING:</pre>
1018</dt><dd><code>STRING</code> should be the name of a global variable holding a callback, or an expression
1019evaulating to a procedure or name.
1020
1021</dd></dl>
1022
1023</dd></dl>
1024
1025<p></p></li><li><b><i>SXML interface</i></b>
1026
1027<dl><dt><pre><b>[procedure] (bb:render SXML)</b></pre>
1028</dt><dd>Creates the widgets defined by the <a href="http://okmij.org/ftp/Scheme/xml.html">SXML</a> representation in <code>SXML</code>.
1029Each element represents a widget where the tag specifies a widget type (as in <code>bb:make-widget</code>).
1030Element attributes represent widget properties. Attribute-value strings are transformed according to the following
1031mapping:
1032
1033<p></p><dl><dt><code>x y width height spacing maximum minimum x-position y-position text-size</code></dt><dd>numeric string.
1034<code>x, y, width</code> and <code>height</code> may also be specified as offsets given as strings prefixed with <code>+</code> or
1035<code>-</code>, or percentages given as strings suffixed with <code>%</code>.
1036</dd><dt><code>color text-color selection-color</code></dt><dd>A string of the form <code>#RRGGBB</code> or a color name
1037</dd><dt><code>resizable visible focus modal read-only valid-context</code></dt><dd>anything different from the string
1038  <code>no</code> means true
1039</dd><dt><code>resizable-widget</code></dt><dd>an element id
1040</dd><dt><code>when</code></dt><dd>A comma-separated list of indicator-names
1041</dd></dl>
1042
1043<p>Anything else is either treated as a numeric string or (if not a valid number) as a symbolic property value.
1044Note that attribute values may also be of other types than strings. The content of an SXML element will be
1045used as the <code>text</code> property value of the created widget, if given.
1046<br>Elements may have any number of additional attributes. The attribute <code>id</code> can be used to identify
1047elements.
1048<br>A child widget will have the dimensions of it's parent, if no <code>width</code> and/or <code>height</code>
1049attributes are given.
1050
1051</p></dd><dt><pre><b>[procedure] (bb:element? X)</b></pre>
1052</dt><dd>Returns <code>#t</code> if <code>X</code> is an element, or <code>#f</code> otherwise.
1053
1054</dd><dt><pre><b>[procedure] (bb:element-widget ELEMENT)
1055[procedure] (bb:element-parent ELEMENT)
1056[procedure] (bb:element-children ELEMENT)
1057[procedure] (bb:element-id ELEMENT)
1058[procedure] (bb:element-tag ELEMENT)
1059[procedure] (bb:element-content ELEMENT)
1060[procedure] (bb:element-attributes ELEMENT)</b></pre>
1061</dt><dd>Accessor procedures for element slots. Parent is an element or <code>#f</code> (if its the root element).
1062Children is a list of child elements. Widget is the widget represented by this element. Id and tag are symbols.
1063Attributes is a property list mapping attribute symbols to values. Content is a string.
1064
1065</dd><dt><pre><b>[procedure] (bb:find-element ID [ROOT])</b></pre>
1066</dt><dd>Searches the element with the id <code>ID</code>, starting from parent element <code>ROOT</code>, or
1067the value of <code>(bb:root-element)</code> if not given. If no element with this id can be found <code>#f</code>
1068is returned.
1069
1070</dd><dt><pre><b>[procedure] (bb:find-widget ID [ROOT])</b></pre>
1071</dt><dd>Equivalent to <code>(bb:element-widget (bb:find-element ID ROOT))</code>.
1072
1073</dd><dt><pre><b>[parameter] (bb:root-element [ELEMENT])</b></pre>
1074</dt><dd>Parameter holding the current root element.
1075
1076</dd></dl>
1077
1078</li></ul>
1079
1080<p></p><h3>Examples:</h3>
1081
1082<p>Hello, world:
1083
1084</p><pre>(require-extension srfi-17 bb)
1085
1086(bb:init)
1087
1088(define w (bb:make-widget 'window 200 100))
1089
1090(bb:group
1091 w
1092 (lambda ()
1093   (let ([lbl (bb:make-widget 'label 200 100)])
1094     (set! (bb:property lbl 'box) 'engraved-box)
1095     (set! (bb:property lbl 'text-size) 32)
1096     (set! (bb:property lbl 'text-font) 'times-bold-italic)
1097     (set! (bb:property lbl 'text) "Hello, World") ) ) )
1098
1099(bb:show w)
1100
1101;An alternative, simpler way of doing the above:
1102;
1103;(bb:render
1104; '(window (@ (width 200) (height 100))
1105;         (label (@ (box engraved-box) (text-size 32) (text-font times-bold-italic))
1106;                "Hello, World")))
1107
1108(bb:run)
1109</pre>
1110
1111<p>A very simple shell:
1112
1113</p><pre>(require-extension extras posix srfi-17 bb)
1114
1115(bb:init)
1116
1117(define width 300)
1118(define height 150)
1119
1120(define w (bb:make-widget 'window width height))
1121
1122(define str #&lt;&lt;EOF
1123LLLLLLLLLLLLLJJJJJJJ
1124LLLLLLLLLLLLLJJJJJJJ
1125LLLLLLLLLLLLLJJJJJJJ
1126EEEEEEEEEEEEEEEEEEEE
1127EOF
1128)
1129
1130(define widgets
1131  (bb:group
1132   w
1133   (lambda ()
1134     (bb:make-widgets str width height) ) ) )
1135
1136(define lst (cdr (assq #\L widgets)))
1137(define entry (cdr (assq #\E widgets)))
1138
1139(set! (bb:property entry 'callback)
1140  (lambda ()
1141    (let ([cmd (bb:property entry 'text)])
1142      (bb:add! lst (string-append "@i@." cmd))
1143      (set! (bb:property entry 'text) "")
1144      (with-input-from-pipe
1145       cmd
1146       (lambda ()
1147         (let loop ()
1148           (let ([ln (read-line)])
1149             (unless (eof-object? ln)
1150               (bb:add! lst (string-append "@." ln))
1151               (loop) ) ) ) ) ) ) ) )
1152
1153(bb:show w)
1154(bb:run)
1155</pre>
1156
1157<p>A simple "notes" application:
1158
1159</p><pre>(require-extension utils srfi-17 bb)
1160
1161(bb:init)
1162
1163(define (switch-note)
1164  (let ([item (bb:property item-list 'value)])
1165    (when (&gt; item 0)
1166      (let ([note (list-ref all-notes (sub1 item))])
1167        (note-hidden?-set! note #f)
1168        (bb:show (note-window note)) ) ) ) )
1169
1170(bb:render
1171 `(window (@ (width 200) (height 300) (resizable) (id w) (resizable-widget lst))
1172          (menu-bar (@ (height 30) (id m)))
1173          (list (@ (y 30) (width 200) (height 270) (id lst) (callback switch-note))) ) )
1174
1175(define item-list (bb:find-widget 'lst))
1176(define menu-bar (bb:find-widget 'm))
1177(define notes-window (bb:find-widget 'w))
1178(define default-color 'yellow)
1179(define all-notes '())
1180
1181(define-record note window edit title color hidden?)
1182
1183(define (note-hider note)
1184  (lambda ()
1185    (note-hidden?-set! note #t)
1186    (set! (bb:property (note-window note) 'visible) #f) ) )
1187
1188(define (add-note . title)
1189  (let* ([name (:optional title (-&gt;string (gensym 'note)))]
1190         [x (random 600)]
1191         [y (random 400)]
1192         [w (bb:make-widget 'window x y 200 150)]
1193         [e (bb:group w (lambda () (bb:make-widget 'edit 0 0 200 150)))]
1194         [note (make-note w e name default-color #f)] )
1195    (set! (bb:property w 'resizable) #t)
1196    (set! (bb:property w 'resizable-widget) e)
1197    (set! (bb:property e 'color) default-color)
1198    (set! (bb:property w 'callback) (note-hider note))
1199    (bb:show w)
1200    (bb:add! item-list (sprintf "@.~A" name))
1201    (set! all-notes (append all-notes (list note))) ) )
1202
1203(define (choose-color)
1204  (and-let* ([col (bb:select-color default-color)])
1205    (set! default-color col) ) )
1206
1207(define notesfile (make-pathname (getenv "HOME") ".bbnotes"))
1208
1209(define (load-notes . file)
1210  (with-input-from-file (:optional file notesfile)
1211    (lambda ()
1212      (match (read)
1213        [(x y w h)
1214         (set! (bb:property notes-window 'x) x)
1215         (set! (bb:property notes-window 'y) y)
1216         (set! (bb:property notes-window 'width) w)
1217         (set! (bb:property notes-window 'height) h) ] )
1218      (let loop ()
1219        (match (read)
1220          [(? eof-object?) #f]
1221          [(title color pos text hidden?)
1222           (let* ([w (apply bb:make-widget 'window pos)]
1223                  [e (bb:group w (lambda () (apply bb:make-widget 'edit 0 0 (cddr pos))))]
1224                  [note (make-note w e title color hidden?)] )
1225             (set! (bb:property e 'color) color)
1226             (set! (bb:property w 'resizable) #t)
1227             (set! (bb:property w 'resizable-widget) e)
1228             (set! (bb:property w 'text) title)
1229             (set! (bb:property w 'callback) (note-hider note))
1230             (bb:add! e text)
1231             (unless hidden? (bb:show w))
1232             (set! all-notes (append all-notes (list note)))
1233             (bb:add! item-list (string-append "@." title))
1234             (loop) ) ] ) ) ) ) )
1235
1236(define (save-notes . file)
1237  (with-output-to-file (:optional file notesfile)
1238    (lambda ()
1239      (write (map (cut bb:property notes-window &lt;&gt;) '(x y width height)))
1240      (newline)
1241      (for-each
1242       (lambda (note)
1243         (let ([w (note-window note)]
1244               [e (note-edit note)] )
1245           (write
1246            (list
1247             (note-title note)
1248             (note-color note)
1249             (list (bb:property w 'x) (bb:property w 'y) (bb:property w 'width) (bb:property w 'height))
1250             (bb:property e 'text)
1251             (note-hidden? note) ) )
1252           (newline) ) )
1253       all-notes) ) ) )
1254
1255(define (change-title)
1256  (let ([i (bb:property item-list 'value)])
1257    (when (&gt; i 0)
1258      (let* ([note (list-ref all-notes (sub1 i))]
1259             [title (bb:get-input "Enter new title" (note-title note))] )
1260        (set! (bb:property (note-window note) 'text) title)
1261        (note-title-set! note title)
1262        (update-list) ) ) ) )
1263
1264(define (update-list)
1265  (bb:remove! item-list #t)
1266  (for-each (lambda (note) (bb:add! item-list (string-append "@." (note-title note)))) all-notes) )
1267
1268(define (change-color)
1269  (let ([i (bb:property item-list 'value)])
1270    (when (&gt; i 0)
1271      (let* ([note (list-ref all-notes (sub1 i))]
1272             [col (bb:select-color (note-color note))] )
1273        (set! (bb:property (note-edit note) 'color) col)
1274        (bb:redraw (note-edit note))
1275        (note-color-set! note col) ) ) ) )
1276
1277(define (fini)
1278  (save-notes)
1279  (exit) )
1280
1281(set! (bb:property notes-window 'callback) fini) ; when ESC is pressed
1282
1283(bb:add! menu-bar "File/Quit" fini "^q")
1284(bb:add! menu-bar "Notes/New" add-note "^n")
1285(bb:add! menu-bar "Notes/Set default color..." choose-color)
1286(bb:add! menu-bar "Change/Title..." change-title)
1287(bb:add! menu-bar "Change/Color..." change-color)
1288
1289(bb:show notes-window)
1290
1291(when (file-exists? notesfile) (load-notes))
1292
1293(bb:run)
1294</pre>
1295
1296<p>Event handlers usage:
1297
1298</p><pre>(require-extension srfi-17 bb)
1299(bb:init)
1300(define w (bb:make-widget 'window 200 100))
1301(define e (bb:make-widget 'edit 5 5 150 25))
1302(set! (bb:property e 'callback) (lambda () (display "edit was changed") (newline) ) )
1303(set! (bb:property e 'when) 'changed)
1304(set! (bb:property e 'handler)
1305  (lambda (e)
1306    (case e
1307      [(move)
1308       (printf "mouse was moved over edit at (~A, ~A)~%" (bb:event 'x) (bb:event 'y))
1309       #t]
1310      [(push)
1311       (printf "mouse was clicked on edit, clicks = 1 + ~A~%" (bb:event 'clicks))
1312       (set! (bb:event 'clicks) 0)
1313       (printf "clicks after setting: ~A~%" (bb:event 'clicks))
1314       #t]
1315      [(keydown)
1316       (printf "key was pressed: ~A~%" (bb:event 'key))
1317       -1]
1318      [else -1] ) ; pass other events to the base class
1319    ) )
1320
1321(bb:show w)
1322(bb:run)
1323</pre>
1324
1325<h3>License:</h3>
1326<pre>Copyright (c) 2004, Felix L. Winkelmann
1327All rights reserved.
1328
1329Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
1330conditions are met:
1331
1332  Redistributions of source code must retain the above copyright notice, this list of conditions and the following
1333    disclaimer.
1334  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
1335    disclaimer in the documentation and/or other materials provided with the distribution.
1336  Neither the name of the author nor the names of its contributors may be used to endorse or promote
1337    products derived from this software without specific prior written permission.
1338
1339THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
1340OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
1341AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
1342CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1343CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1344SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1345THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
1346OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1347POSSIBILITY OF SUCH DAMAGE.
1348</pre>
1349
1350
1351<hr><a href="http://www.call-with-current-continuation.org/eggs/index.html">back</a>
1352
1353</body></html>
Note: See TracBrowser for help on using the repository browser.